akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct state { long long a, b; };
inline bool operator<(const state& s1, const state& s2) { return s1.a < s2.a; }
int N; long long D, A[33], B[33];
state vl[7777777], vr[7777777]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Meet-in-the-middle Algorithm
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}
	int cnt1 = 0, cnt3 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	int cnt2 = 0, cnt4 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}
	sort(vl, vl + cnt1); cnt1 += cnt3;
	sort(vr, vr + cnt2); cnt2 += cnt4;
	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;

	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while ((dr - dl) && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if ((dr - dl) && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681920
#include <bits/stdc++.h>
#define MOD 1000000007

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int m = ri();
	int q = ri();
	std::string s[n];
	for (int i = 0; i < n; i++) std::cin >> s[i];
	
	std::vector<std::vector<int> > k(n + 1, std::vector<int>(m + 1));
	std::vector<std::vector<int> > yok(n, std::vector<int>(m + 1));
	std::vector<std::vector<int> > tat(n + 1, std::vector<int>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i][j] == '1') {
				k[i + 1][j + 1]++;
				if (i + 1 < n && s[i + 1][j] == '1') yok[i + 1][j + 1]++;
				if (j + 1 < m && s[i][j + 1] == '1') tat[i + 1][j + 1]++;
			}
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			k[i + 1][j] += k[i][j];
			if (j < m) tat[i + 1][j] += tat[i][j];
			if (i + 1 < n) yok[i + 1][j] += yok[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < m; j++) {
			k[i][j + 1] += k[i][j];
			if (i < n) yok[i][j + 1] += yok[i][j];
			if (j + 1 < m) tat[i][j + 1] += tat[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			std::cerr << yok[i][j] << " ";
		}
		std::cerr << std::endl;
	}
	for (int i = 0; i < q; i++) {
		int x1 = ri() - 1, y1 = ri() - 1, x2 = ri() - 1, y2 = ri() - 1;
		int res = k[x2 + 1][y2 + 1] - k[x2 + 1][y1] - k[x1][y2 + 1] + k[x1][y1];
		res -= yok[x2][y2 + 1] - yok[x1][y2 + 1] - yok[x2][y1] + yok[x1][y1];
		res -= tat[x2 + 1][y2] - tat[x1][y2] - tat[x2 + 1][y1] + tat[x1][y1];
		std::cout << res << std::endl;
	}
	
	return 0;
}



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

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

constexpr int MAX_N = 1e5+7;
constexpr int INF = 1e9+7;

int h[MAX_N];
int dp[MAX_N];

int main() {
  int N; cin >> N;
  for (int i{}; i < N; ++i) cin >> h[i];

  fill_n(dp, MAX_N, INF);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i{2}; i < N; ++i) {
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


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

using namespace std;

const int N = 2e5 + 5;
int n, f[N][2];
char c[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> c + 1;
  f[0][0] = f[0][1] = 0;
  for (int i = 1; i <= n; ++i) {
    f[i][0] = f[i - 1][0];
    f[i][1] = f[i - 1][1];
    if (c[i] == 'R') f[i][0]++;
    else f[i][1]++;
  }
  int ans = 1e9 + 7;
  for (int i = 0; i <= n; ++i) { ///red: [1 -> i]
    int redL = f[i][0], redR = f[n][0] - f[i][0];
    int whiteL = f[i][1], whiteR = f[n][1] - f[i][1];
    ans = min(ans, max(whiteL, redR));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5368
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>

using namespace std;

int main(){
	long long int n,x;
	cin >> n >> x;
	long long int t[n], c = 0;
	for(int i = 0 ; i < n; i++){
		cin >> t[i];
	}
	
	for(int i = 1; i < n; i++){
		if(t[i] - t[i-1] < x){
			c += t[i] - t[i-1];
		}
		else{
			c += x;
		}
	}
	c += x;
	
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 1792
n, k = list(map(int, input().split()))
# 先頭に0番要素を追加すれば、配列の要素番号と入力pが一致する
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

ans = -float('inf')
# 開始ノードをsi
for si in range(1, n+1):

    # 閉ループのスコアを取り出す
    x = si
    s = list()  # ノードの各スコアを保存
    #s_len = 0
    tot = 0     # ループ1周期のスコア
    while 1:
        x = p[x]
        s.append(c[x])
        #s[s_len] = c[x]
        #s_len += 1
        tot += c[x]
        if (x == si): break # 始点に戻ったら終了
    
    # siを開始とする閉ループのスコア(s)を全探
    s_len = len(s)
    t = 0
    for i in range(s_len):
        t += s[i]   # i回移動したときのスコア
        if (i+1 > k): break # 移動回数の上限を超えたら終了
        # 1周期のスコアが正ならば、可能な限り周回する
        if tot > 0:
            e = (k-(i+1))//s_len # 周回数
            now = t + tot*e      # i回移動と周回スコアの合計
        else:
            now = t
        ans = max(ans, now)

print(ans)


Measured memory_bytes: 81252
#include<bits/stdc++.h>
#define ll long long
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int s[N];
main()
{
    int n;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        int x;
        cin>>x;
        s[x]++;
    }
    for(int i=1;i<=n;i++)
        cout<<s[i]<<' ';


}



Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    ll n, m;
    ll ans = 0;
    rep(i, N)
    {
        ll t, a;
        cin >> t >> a;
        if (i == 0)
        {
            n = t;
            m = a;
        }
        else
        {
            ll k = max((m + a - 1) / a, (n + t - 1) / t);
            m = k * a;
            n = (m / a) * t;
        }
    }
    cout << n + m;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const double INF=1e5;
const double EPS=1.0e-10;
const double PI=M_PI;

struct Point {double x,y;};
struct Line {double a,b,c;};
struct Circle {double r; Point p;};

//2点間の距離
double kyori(Point p,Point q){
    return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}

//点と直線の符号付距離
double dist(Point p, Line l){
    return -(l.a*p.x+l.b*p.y+l.c)/sqrt(l.a*l.a+l.b*l.b);
}

//円と直線の交点
vector<Point> LCInter(Circle cir,Line l){
    vector<Point> res;
    double d=dist(cir.p,l);
    if(fabs(d)>cir.r) return res;
    double h=sqrt(cir.r*cir.r-d*d);
    Point H={d*l.a/sqrt(l.a*l.a+l.b*l.b)+cir.p.x,d*l.b/sqrt(l.a*l.a+l.b*l.b)+cir.p.y};
    res.push_back({H.x-h*l.b/sqrt(l.a*l.a+l.b*l.b),H.y+h*l.a/sqrt(l.a*l.a+l.b*l.b)});
    res.push_back({H.x+h*l.b/sqrt(l.a*l.a+l.b*l.b),H.y-h*l.a/sqrt(l.a*l.a+l.b*l.b)});
    return res;
}

//2円の交点
vector<Point> CCInter(Circle c1,Circle c2){
    Line l={2.0*(c1.p.x-c2.p.x),2.0*(c1.p.y-c2.p.y),
    -c1.p.x*c1.p.x-c1.p.y*c1.p.y+c2.p.x*c2.p.x+c2.p.y*c2.p.y+c1.r*c1.r-c2.r*c2.r};
    return LCInter(c1,l);
}

int N; vector<Point> p;
bool b(double r){
    rep(i,N){
        FOR(j,i+1,N){
            vector<Point> v=CCInter(Circle{r,p[i]}, Circle{r,p[j]});
            rep(k,SZ(v)){
                bool res=true;
                rep(l,N){
                    if(l==i || l==j) continue;
                    if(kyori(v[k],p[l])>r){
                        res=false;
                        break;
                    }
                }
                if(res) return true;
            }
        }
    }
    return false;
}

double BS(double l,double r){
    if(r-l<EPS) return r;
    double m=(l+r)/2.0;
    if(b(m)) return BS(l,m);
    else     return BS(m,r);
}

int main(){
    cin>>N; p.resize(N);
    rep(i,N) cin>>p[i].x>>p[i].y;
    printf("%.10lf\n",BS(0.0,INF));
    return 0;
}

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

# hを体力の小さい順にソート
h.sort()

# 全てのモンスターに必殺技を使える場合
if k >= len(h):
    print('0')
# 全てのモンスターに必殺技を使えない場合
# 体力の大きいモンスター順からk体削除
else:
    new_h = h[:len(h)-k]
    print(sum(new_h))


Measured memory_bytes: 26180
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    long long n, m, d; cin >> n >> m >> d;
    double r = (2.0 * (n - d) / n) / n;
    if (d == 0) r = 1.0 / n;

    cout << std::fixed << std::setprecision(15);
    cout << r * (m - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
//long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;
/*
string change_hands(string U, char c, int K){
    for(int i=K; i<U.size();i++){
        if(U[i-K] == U[i]){
            if(U[i] == 'r'){
                sum -= R;
            }else if(U[i] == 's'){
                sum -= S;
            }else{
                sum -= P;
            }
        }
    }
}*/

int main(){
    long long N,M;
    cin >> N >> M;
    vector<long long> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end(), std::greater<int>());
    vector<long long> S(N);
    S[0] = A[0];
    rep(i,N-1){
        S[i+1] = S[i] + A[i+1];
    }
    /*rep(i,N){
        cout << S[i] << endl;
    }*/

    ll L=0,R=1e10+1;
    ll sum = 0;
    while(L+1 < R){
        ll X = (L+R)/2;
        ll tot = 0;
        sum = 0;
        rep(i,N){
            ll l=-1, r=N;
            while(l+1<r){
                ll x = (l+r)/2;
                if(A[i] + A[x] >= X) l = x; else r = x;
            }
            //A[i] + A[]
            //cout <<"r:"<<r <<endl;
            if(r==0)continue;
            tot += r;
            //cout << "S[r-1]:"<<S[r-1] << " r:" << r<<endl;
            sum += S[r-1] + A[i]*r;
            //cout << sum << endl
        }
        if(tot >= M) L = X; else R = X;
    }
    ll X = L;
    //cout << "R:"<<R<<endl;
    sum = 0;
    ll tot = 0;
    ll a;
    rep(i,N){
        ll l=-1, r=N;
        while(l+1<r){
            ll x = (l+r)/2;
            if(A[i] + A[x] >= X) l = x; else r = x;
        }
        //A[i] + A[]
        //cout <<"r:"<<r <<endl;
        if(r==0)continue;
        tot += r;
        //cout << "S[r-1]:"<<S[r-1] << " r:" << r<<endl;
        sum += S[r-1] + A[i]*r;
        //cout << sum << endl;
        a = l;
    }
    //cout << "a:"<<a << endl;
    sum -= X*(tot-M);

    cout << sum << endl;
}



Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int n,a,b;
	scanf("%d",&n);
	a=n/10;
	b=n%10;
	if(a==9){
		printf("Yes\n");
	}
	else if(b==9){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
while gets
	a = $_.chomp.split.map { |i| i.to_i }
	b = gets.chomp.split.map { |i| i.to_i }
	hit = 0
	for i in 0..a.size-1
		if a[i] == b[i]
			hit += 1 
		end
	end
	blow = (a&b).size - hit
	print hit
	print ' '
	print blow
	puts ''
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

enum RESULT{
	different,
	pre_shorter,
	pre_longer,
};

char table[26][26];

struct Info{
	char pre,current;
	RESULT result;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

Info compare(char pre[11],char current[11]){
	Info info;

	int pre_length,current_length;

	for(pre_length = 0;pre[pre_length] != '\0';pre_length++);
	for(current_length = 0; current[current_length] != '\0';current_length++);

	int index;

	for(index = 0;pre[index] == current[index] && index < pre_length && index < current_length ;index++);

	if(index == pre_length && index == current_length){
		info.result = pre_shorter;
	}else if(index != pre_length && index == current_length){
		info.result = pre_longer;
	}else if(index == pre_length && index != current_length){
		info.result = pre_shorter;
	}else{

		info.result = different;
		info.pre = pre[index];
		info.current = current[index];
	}

	return info;
}


int main(){

	int N;
	char pre[11],current[11];
	bool FLG;
	Info reason;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < 26; i++){
			for(int k = 0; k < 26; k++){
				if(i != k){
					table[i][k] = '?';
				}else{
					table[i][k] = 'a'+ i;
 				}
			}
		}

		FLG = true;

		scanf("%s",pre);

		for(int i = 1; i < N; i++){
			scanf("%s",current);

			if(FLG){
				reason = compare(pre,current);
				if(reason.result == pre_longer){
					FLG = false;
				}else if(reason.result == different){

					if(table[reason.pre-'a'][reason.current-'a'] == '?'){

						for(int k = 0; k < 26; k++){
							if(table[k][reason.pre-'a'] == 'a'+k && table[k][reason.current-'a'] == reason.current){
								FLG = false;
								break;
							}
						}

						table[reason.pre-'a'][reason.current-'a'] = reason.pre;
						table[reason.current-'a'][reason.pre-'a'] = reason.pre;

						for(int me = 0;me < 26; me++){
							for(int you = 0; you < 26; you++){
								if(me != you && table[me][you] == 'a' + me){
									for(int other = 0; other < 26; other++){
										if(you != other && table[you][other] == 'a' + you){
											table[me][other] = 'a' + me;
											table[other][me] = 'a' + me;
										}
									}
								}
							}
						}

					}else if(table[reason.pre-'a'][reason.current-'a'] == reason.pre){
						//Do nothing
					}else{
						FLG = false;
					}
				}
				strcpy(pre,current);
			}
		}

		if(FLG)printf("yes\n");
		else{
			printf("no\n");
		}
	}

	return 0;
}

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

int main() {
  int n; cin >> n;
  int m = 3 * n;
  vector<int> a(m);
  for (int i = 0; i < m; ++i) cin >> a[i];
  priority_queue<int, vector<int>, greater<int>> pq;
  vector<long long> sum(m);
  for (int i = 0; i < m; ++i) {
    pq.push(a[i]);
    sum[i] = a[i] + (i > 0 ? sum[i - 1] : 0);
    while (pq.size() > n) {
      sum[i] -= pq.top();
      pq.pop();
    }
  }
  priority_queue<int, vector<int>, less<int>> hp;
  long long s = 0, ans = -1e18;
  for (int i = m - 1; i >= 0; --i) {
    hp.push(a[i]);
    s += a[i];
    while (hp.size() > n) {
      s -= hp.top();
      hp.pop();
    }
    if (hp.size() == n && i - 1 >= n - 1) {
      ans = max(ans, sum[i - 1] - s);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
    ll res=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
    return res*f;
}
void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10|'0');
}
const int N=1007;
const int mod=1e9+7;
int f[N][N],n,m;
char a[N][N];
signed main(){
    n=read(),m=read();
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++) cin>>a[i][j];
    for(int i=1;i<=n;i++) if(a[i][1]=='#')break;else f[i][1]=1;
    for(int i=1;i<=m;i++) if(a[1][i]=='#')break;else f[1][i]=1;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=m;j++) if(a[i][j]!='#')f[i][j]=f[i-1][j]+f[i][j-1],f[i][j]%=mod;
//    for(int i=1;i<=n;i++){for(int j=1;j<=m;j++) cout<<f[i][j]<<" ";cout<<endl;
//    }
    cout<<f[n][m]%mod<<endl;
}


Measured memory_bytes: 9088
module Resistors_in_Parallel
  sub Main(ByVal args() as String)
    dim a as integer
    a=Console.ReadLine()
    dim arr(a) as string
    arr=Split(Console.ReadLine())
    dim bb as double
    for i as integer = 0 to a-1
    bb+= 1/integer.parse(arr(i))
  next i
  dim ans as double = 1/bb

    Console.WriteLine(ans)
  end sub
end module

Measured memory_bytes: 11488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll n,m,s[2005],t[2005],dp[2005][2005];

int main() {
    cin >> n >> m;
    REP(i,n) cin >> s[i];
    REP(i,m) cin >> t[i];

    dp[0][0] = 1;
    REP(i,n+1){
        REP(j,m+1){
            dp[i][j] %= MOD;
            if(s[i]==t[j]){
                dp[i+1][j+1] += dp[i][j];
            }
            dp[i+1][j] += dp[i][j];
            dp[i][j+1] += dp[i][j];
            dp[i+1][j+1] -= dp[i][j];
            dp[i+1][j+1] += MOD;
            dp[i+1][j+1] %= MOD;
            dp[i+1][j] %= MOD;
            dp[i][j+1] %= MOD;

        }
    }
    cout << dp[n][m]%MOD << endl;
    return 0;
}


Measured memory_bytes: 31616
/*
    Problem 26
    https://atcoder.jp/contests/abc138/tasks/abc138_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 200005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
vector<bool> visited(MAX);
vector<int> counter(MAX, 0);
/* function */
void bfs(int st) {
    queue<int> q;
    q.push(st);
    visited[st] = true;
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to : G[from]) {
            if (visited[to]) continue;
            visited[to] = true;
            counter[to] += counter[from];
            q.push(to);
        }
    }
}
/* main */
int main(){
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < Q; i++) {
        int a, c;
        cin >> a >> c;
        a--;
        counter[a] += c;
    }
    bfs(0);

    for (int i = 0; i < N; i++)
        cout << counter[i] << (i == N-1 ? '\n' : ' ');
}

Measured memory_bytes: 16616
#include<bits/stdc++.h>
using namespace std;
long long n;
long long dp[6000],pd[26000000];
long long a[4],b[4];
long long v;
vector<int> ok;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=3;i++)
		cin>>a[i];
	for(int i=1;i<=3;i++)
		cin>>b[i];
	{
	if(a[1]<b[1])
		ok.push_back(1);
	if(a[2]<b[2])
		ok.push_back(2);
	if(a[3]<b[3])
		ok.push_back(3);
	memset(dp,-1,sizeof(dp));
	dp[n]=0;
	for(int i=n;i>=1;i--){
		if(dp[i]==-1)
			continue;
		for(int j=0;j<ok.size();j++){
			if(i>=a[ok[j]])
				dp[i-a[ok[j]]]=max(dp[i-a[ok[j]]],dp[i]+b[ok[j]]);
		}
		v=max(v,dp[i]+i);
	}
	v=max(v,dp[0]);
	}
	{
	n=v;
	memset(pd,-1,sizeof(pd));
	pd[n]=0;
	ok.clear();
	if(a[1]>b[1])
		ok.push_back(1);
	if(a[2]>b[2])
		ok.push_back(2);
	if(a[3]>b[3])
		ok.push_back(3);
	for(int i=n;i>=1;i--){
		if(pd[i]==-1)
			continue;
		for(int j=0;j<ok.size();j++){
			if(i>=b[ok[j]])
				pd[i-b[ok[j]]]=max(pd[i-b[ok[j]]],pd[i]+a[ok[j]]);
		}
		v=max(v,pd[i]+i);
	}
	v=max(v,pd[0]);
	}
	cout<<v<<endl;
	return 0;
}


Measured memory_bytes: 203392
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    int h, n;
    scanf("%d %d", &h, &n);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        h -= a;
        if (h <= 0) {
            printf("Yes\n");
            return EXIT_SUCCESS;
        }
    }
    printf("No\n");
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include<iostream>

int main() {
	int n,a[100],i;

	std::cin >> n;

	for (i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	for (i = n - 1; i >= 0; i--) {
		std::cout << a[i] ;
		if (i != 0) {
			std::cout << " ";

		}
	}

	std::cout << std::endl;

	return 0;
}


Measured memory_bytes: 3116
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using mp_int = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using mp_float = mp::number<mp::cpp_dec_float<1024>>;

int main(){
	mp_int X;
	cin >> X;

	mp_int ans = 0;
	mp_int M = 100;
	while(1) {
		ans++;
		M = M * 101 / 100;
		//cout << M << endl;
		if (M >= X) {
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3656
#!/usr/bin/env python
# coding: utf-8

# In[15]:


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


# In[17]:


total = sum(A)
ans = total
left = 0
for i in A:
    left += i
    right = total - left
    ans = min(ans, abs(left - right))
#     print(left, right, ans)
print(ans)


# In[ ]:






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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

typedef int64_t ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int64_t arr[201][201];

void init() {
    for (int i = 1; i <= 200; ++i) {
        for (int j = 1; j <= 200; ++j) {
            arr[i][j] = gcd(i, j);
        }
    }
}

int main() {
    int K; cin >> K;
    int64_t sum = 0;
    init();
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            int64_t t = arr[i][j];
            for (int k = 1; k <= K; ++k) {
                sum += arr[t][k];
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;

string Main(int &n)
{
    if(n >= 1 && n <= 9)
    {
        return "Yes";
    }
    else
    {
        REP2(i, 2, 10)
        {
            if(n % i == 0)
            {
                int d = n / i;
                if(d >= 1 && d <= 9)
                {
                    return "Yes";
                }
            }
        }
        return "No";
    }
}


int main(void){
    int N;
    cin >> N;
    cout << Main(N) << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from itertools import permutations

def solve():
    n = int(input())
    cord = [list(map(int, input().split())) for _ in range(n)]
    # print(cord)
    # dist = {}
    # for i in range(n):
    #     for j in range(n):
    #         if i == j: continue
    #         d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2))
    #         dist[(i, j)] = d
    # print(dist)
    sm = 0
    for cnt, i in enumerate(permutations(range(n))):
        # print(i)
        for j in range(1, n):
            # print('aaa', i[j-1], i[j])
            # d = dist[(i[j-1], i[j])]
            s = i[j-1]
            t = i[j]
            d = math.sqrt(pow(cord[s][0] - cord[t][0], 2) + pow(cord[s][1] - cord[t][1], 2))
            # print(d)
            sm = sm + d
    print(sm / (cnt+1))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
// @author: arch_

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

vector<string> split(const string& str, char sep) {
    vector<string> v;
    stringstream s(str);
    string buf;
    while (getline(s, buf, sep)) v.emplace_back(buf);
    return v;
}

int main(void) {
    vector<vector<string>> d;
    string s; 
    while (getline(cin, s)) {
        auto&& i = split(s, ' ');
        if (i[1] == "?") break;
        d.emplace_back(i);
    }
    int a, b;
    for (auto&& v : d) {
        a = stoi(v[0]); b = stoi(v[2]);
        cout << (v[1] == "+" ? a + b :
                 v[1] == "-" ? a - b :
                 v[1] == "*" ? a * b :
                 static_cast<int>(a / b)) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3224
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[200005],x,y;

pi b[200005];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        b[i]={a[i],i};
    }
    sort(b+1,b+n+1);
    int x=b[n/2].y,y=b[n/2+1].y;
    for(int i=1;i<=n;i++){
        if(a[i]<=a[x]) cout << a[y] << '\n';
        else cout << a[x] << '\n';
    }
}


Measured memory_bytes: 4608
//????????????????????????
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, pii> ver;
typedef pair<int, ver> piv;
int dx[2][4] = {{1, 0, -1, 0},
                {-1, 0, 1, 0}};
int dy[] = {0, 1, 0, -1};
int dp[51][51][51][51];

bool range(pii p, int w, int h){
  if(0 <= p.first  && p.first  < w &&
     0 <= p.second && p.second < h)return true;
  return false;
}
int main(int argc, char *argv[]){
  int w, h;
  while(cin >> w >> h, w){
    vector<string> grid1(h), grid2(h);
    pii s[2], g[2];
    for (int i = 0; i < h; i++) {
      cin >> grid1[i] >> grid2[i];
      for (int j = 0; j < w; j++) {
        if(grid1[i][j] == 'L')s[0].first = j, s[0].second = i;
        if(grid1[i][j] == '%')g[0].first = j, g[0].second = i;
        if(grid2[i][j] == 'R')s[1].first = j, s[1].second = i;
        if(grid2[i][j] == '%')g[1].first = j, g[1].second = i;
      }
    }
    for (int i = 0; i < h; i++) 
      for (int j = 0; j < w; j++) 
        for (int k = 0; k < h; k++) 
          for (int l = 0; l < w; l++) 
            dp[i][j][k][l] = 1e9;
    
    dp[s[0].second][s[0].first][s[1].second][s[1].first] = 0;
    queue<piv> que;
    que.push(piv(0, ver(s[0], s[1])));
    while(!que.empty()){
      pii u = que.front().second.first;
      pii v = que.front().second.second;
      int c = que.front().first;
      que.pop();
      if(u == g[0] && v == g[1])break;
      for (int i = 0; i < 4; i++) {
        pii a = u, b = v;
        a.first  += dx[0][i];
        a.second += dy[i];
        b.first  += dx[1][i];
        b.second += dy[i];
        if(!range(a, w, h) || grid1[a.second][a.first] == '#')
          a = u;
        if(!range(b, w, h) || grid2[b.second][b.first] == '#')
          b = v;
        if(a != g[0] || b != g[1]){
          if(a == g[0] || b == g[1])continue;
        }
        if(dp[a.second][a.first][b.second][b.first] > c + 1){
          dp[a.second][a.first][b.second][b.first] = c + 1;
          que.push(piv(c + 1, ver(a, b)));
        }
      }
    }

    if(dp[g[0].second][g[0].first][g[1].second][g[1].first]
       != 1e9)
      std::cout << "Yes" << std::endl;
    else
      std::cout << "No" << std::endl;
  }
  return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string n;
  cin >> n;
  cout << (n[0] == n[2] ? "Yes" : "No") << endl;
}



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

int main(void){
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r;
    else
        cout << r + (100 * (10-n));
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef pair<long long int, int> P;

P count(long long int b, long long int j) {
	P p = P(0, 0);
	for (int i = 0; i < 16; i++) {
		if (((b & (1<<i)) != 0)&&((j & (1<<i)) != 0)) {
			p.second++;
		} else if ((j & (1<<i)) != 0) {
			p.first += (1<<i);
		}
	}
	return p;
}

int main() {
	int n, c;
	while (cin >> n >> c) {
		if (n == 0 && c == 0) {
			break;
		}
		vector<long long int> a(n);
		int cc;
		for (int i = 0; i < n; i++) {
			long long int aa = 0;
			for (int j = 0; j < 16; j++) {
				cin >> cc;
				if (cc == 1) {
					aa += (1<<j);
				}
			}
			a[i] = aa;
		}
		a.push_back((1<<16)-1);
		vector<long long int> b(c);
		for (int i = 0; i < c; i++) {
			long long int bb = 0;
			for (int j = 0; j < 16; j++) {
				cin >> cc;
				if (cc == 1) {
					bb += (1<<j);
				}
			}
			b[i] = bb;
		}
		vector< vector<int> > dp((1<<16), vector<int>(n+1, -1));
		for (int i = 0; i < n; i++) {
			if (i == 0) {
				dp[a[0]][0] = 0;
			}
			for (int j = 0; j < (1<<16); j++) {
				if (dp[j][i] != -1) {
					dp[(a[i+1]|j)][i+1] = max(dp[(a[i+1]|j)][i+1], dp[j][i]);
					for (int k = 0; k < c; k++) {
						P pp = count(b[k], j);
						if (pp.second != 0) {
							dp[(a[i+1]|pp.first)][i+1] = max(dp[(a[i+1]|pp.first)][i+1], dp[j][i]+pp.second);
							//cout << i << ' ' << dp[j][i]+pp.second << endl;
						}
					}
				}
			}
		}
		int MAX = 0;
		for (int i = 0; i < (1<<16); i++) {
			MAX = max(MAX, dp[i][n]);
		}
		cout << MAX << endl;
	}
	return 0;
}

Measured memory_bytes: 11896
#include <iostream>
using namespace std;
int main(){
    int n;cin>>n;
    int a[n];
    for(int i = 0; n > i; i++){
        cin>>a[i];
    }
    int q;cin>>q;
    int ans = 0;
    for(int i = 0; q > i; i++){
        int z;cin>>z;
        int mn = 0;
        int mx = n-1;
        int ce = (mn+mx)/2;
        while(mx-mn > 1 && a[ce] != z){
            if(a[ce] < z){
                mn = ce;
            }else{
                mx = ce;
            }
            ce = (mn+mx)/2;
        }
        if(a[ce] == z)ans++;
        else if(a[mx] == z)ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3440
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringTokenizer s = new StringTokenizer(scan.nextLine());
        int N = Integer.parseInt(s.nextToken());
        int M = Integer.parseInt(s.nextToken());
        int L = Integer.parseInt(s.nextToken());

        long[][] edges = new long[N][N];
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                edges[i][j] = Integer.MAX_VALUE;

        for (int i = 0; i < M; ++i) {
            s = new StringTokenizer(scan.nextLine());
            int A = Integer.parseInt(s.nextToken()) - 1;
            int B = Integer.parseInt(s.nextToken()) - 1;
            int C = Integer.parseInt(s.nextToken());
            edges[A][B] = C;
            edges[B][A] = C;
        }

        for (int k = 0; k < N; ++k) {
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j < N; ++j) {
                    edges[i][j] = Math.min(edges[i][j], edges[i][k] + edges[k][j]);
                }
            }
        }

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                edges[i][j] = (edges[i][j] <= L) ? 0 : Integer.MAX_VALUE;
            }
        }


        for (int k = 0; k < N; ++k) {
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j < N; ++j) {
                    edges[i][j] = Math.min(edges[i][j], edges[i][k] + edges[k][j] + 1);
                }
            }
        }

        int Q = Integer.parseInt(scan.nextLine());
        for (int i = 0; i < Q; ++i) {
            s = new StringTokenizer(scan.nextLine());
            int S = Integer.parseInt(s.nextToken()) - 1;
            int T = Integer.parseInt(s.nextToken()) - 1;

            if (edges[S][T] < Integer.MAX_VALUE)
                System.out.println(edges[S][T]);
            else
                System.out.println(-1);
        }
    }
}


Measured memory_bytes: 153792
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

r,g,b,n = na()
ans=0
for i in range(n//r+1):
    a = n-r*i
    for j in range(a//g+1):
        if (a-g*j)%b == 0:
            ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
typedef long long ll;
typedef long double ld;
const int MAXN = 100005;
char str[MAXN];
bool C[MAXN]; // 0 -> black
int sub1[MAXN], sub2[MAXN];
vector<int> E[MAXN];
void go(int x, int p = -1) {
	int nonblacks = 0;
	int sumsub2 = 0;
	int mndiff = 0;
	int color = 1 - C[x];
	for (int y : E[x]) {
		if (y == p) continue;
		go(y, x);
		if (sub2[y] != -1) {
			sumsub2 += sub2[y] + 2;
			mndiff = min(mndiff, sub1[y] - sub2[y] - 1);
			color = 1 - color;
			++nonblacks;
		}
	}
	if (!nonblacks && !C[x]) sub2[x] = -1;
	else {
		sub2[x] = color + sumsub2;
		sub1[x] = !nonblacks ? 0 : (1 - color) + sumsub2 + mndiff;
	}
}
int ans = INT_MAX;
void come(int x, int p, int psub1, int psub2) {
	int nonblacks = 0;
	int sumsub2 = 0;
	int color = 1 - C[x];
	vector<int> mndiffs;
	for (int y : E[x]) {
		if (y == p) continue;
		if (sub2[y] != -1) {
			sumsub2 += sub2[y] + 2;
			mndiffs.push_back(sub1[y] - sub2[y] - 1);
			color = 1 - color;
			++nonblacks;
		}
	}
	if (psub2 != -1) {
		sumsub2 += psub2 + 2;
		mndiffs.push_back(psub1 - psub2 - 1);
		color = 1 - color;
		++nonblacks;
	}
	sort(mndiffs.begin(), mndiffs.end());
	int val = !nonblacks ? color : (1 - color) + sumsub2 + mndiffs[0];
	ans = min(ans, val + 1);
	for (int y : E[x]) {
		if (y == p) continue;
		if (sub2[y] == -1) continue;
		int ps1 = 0, ps2;
		if (nonblacks == 1 && !C[x]) ps2 = -1;
		else {
			int take = mndiffs[0];
			if (sub1[y] - sub2[y] - 1 == take) take = mndiffs[1];
			int ncolor = 1 - color;
			int nsumsub2 = sumsub2 - sub2[y] - 2;
			ps2 = nsumsub2 + ncolor;
			ps1 = nonblacks == 1 ? 0 : nsumsub2 + take + (1 - ncolor);
		}
		come(y, x, ps1, ps2);
	}
}
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 1; i < N; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		E[x].push_back(y);
		E[y].push_back(x);
	}
	scanf("%s", str);
	for (int i = 0; i < N; ++i) C[i + 1] = str[i] == 'W';
	go(1, -1);
	come(1, -1, 0, -1);
	if (sub2[1] == -1) ans = 0;
	printf("%d\n", ans);
}


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

namespace _0073
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int x = RInt();
                int h = RInt();
                if (x + h == 0) break;

                double th = Math.Sqrt(Math.Pow(x / 2D, 2) + Math.Pow(h, 2D));
                Console.WriteLine(Math.Pow(x, 2D) + x * th * 2);
            }
           
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15900
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 5e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

int main()
{   
    ll n,W;
    cin >> n >> W;
    ll w[n+1],v[n+1];
    FOR(i,1,n)cin >> w[i] >> v[i];
    ll dp[n+1][W+1] = {0};
    FOR(i,0,W)if(i>=w[1])dp[1][i] = v[1]; else dp[1][i] = 0;
    FOR(i,1,n)dp[i][0] = 0;
    FOR(i,2,n){
        FOR(j,1,W){
            if(j>=w[i]){
                dp[i][j] = max(v[i]+dp[i-1][j-w[i]], dp[i-1][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][W];

    return 0;
}

Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n,m,k;
	cin>>n>>m>>k;
	pair<int,int> st;
	cin>>st.F;
	cin>>st.S;
	pair<int,int> de;
	cin>>de.F;
	cin>>de.S;
	string s[n+1];
	for(int i=1;i<=n;++i){
		cin>>s[i];
		s[i]=' '+s[i];
	}
	int ans[n+1][m+1][5]={};
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			ans[i][j][4]=infi;
		}
	}
	priority_queue<pair<pair<int,pair<int,int>>,pair<int,int>>,vector<pair<pair<int,pair<int,int>>,pair<int,int>>>,greater<pair<pair<int,pair<int,int>>,pair<int,int>>>> q;
	q.push({{0,{0,0}},st});
	q.push({{0,{0,1}},st});
	q.push({{0,{0,2}},st});
	q.push({{0,{0,3}},st});
	while(q.size()){
		pair<pair<int,pair<int,int>>,pair<int,int>> p = q.top();
		q.pop();
		pair<int,int> no=p.S;
		if(no.F>n||no.F<1||no.S>m||no.S<1)
			continue;
		if(s[no.F][no.S]!='.')
			continue;
		pair<int,pair<int,int>> va=p.F;
		if(ans[no.F][no.S][4]<va.F){
			continue;
		}
		if(ans[no.F][no.S][4]==va.F){
			if(-ans[no.F][no.S][va.S.S]>=-va.S.F)
				continue;
		}
		ans[no.F][no.S][4]=va.F;
		ans[no.F][no.S][va.S.S]=va.S.F;
		q.push({{va.F+1,{-k+1,0}},{no.F+1,no.S}});
		q.push({{va.F+1,{-k+1,1}},{no.F-1,no.S}});
		q.push({{va.F+1,{-k+1,2}},{no.F,no.S+1}});
		q.push({{va.F+1,{-k+1,3}},{no.F,no.S-1}});

		if(va.S.F!=0){
			if(va.S.S==0)
			q.push({{va.F,{va.S.F+1,va.S.S}},{no.F+1,no.S}});
			if(va.S.S==1)
			q.push({{va.F,{va.S.F+1,va.S.S}},{no.F-1,no.S}});
			if(va.S.S==2)
			q.push({{va.F,{va.S.F+1,va.S.S}},{no.F,no.S+1}});
			if(va.S.S==3)
			q.push({{va.F,{va.S.F+1,va.S.S}},{no.F,no.S-1}});
		}
	}
	if(ans[de.F][de.S][4]==infi){
		cout<<"-1";
	}else
	{
		// if(k==1)
			// ans[de.F][de.S][4]--;
		cout<<ans[de.F][de.S][4];
	}
	#ifdef ANIKET_GOYAL
		// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long> a(n);
    long m = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        m = a[i] * 2 - m;
    }
    m /= 2;
    for (int i = 0; i < n; ++i) {
        cout << m;
        if (i < n - 1) {
            cout << " ";
            m = a[i] * 2 - m;
        }
    }
    cout << endl;
}


Measured memory_bytes: 2048
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 100000000
typedef long long ll;

using namespace std;

int main()
{
    ll x, y,cnt=1;
    cin >> x >> y;
    while (true) {
        x *= 2;
        if (x > y)break;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, l = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for i in range(n)]
b = [[int(j) for j in input().split()] for i in range(m)]
c = [[sum([a[n][m] * b[m][l] for m in range(m)]) for l in range(l)] for n in range(n)]
for ans in c: print(*ans)


Measured memory_bytes: 6984
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a, b, c;
    cin>>a>>b>>c;
    if( 4 * a*b <( c-a-b) * (c-a-b)&&c>(a+b) ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  int N;
  cin>>N;
  if(N%2==0){cout<<0.5000000000<<endl;}
  else{
    double M=(N-1)/2;
    double A=(M+1)/N;
    cout<<fixed;
    cout<<setprecision(11)<<A<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
int main(){
	string s, t;
	cin >> s >> t;
	if (s.size() != t.size()) {
		cout << "No" << endl;
		getchar();
		getchar();
		return 0;
	}
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		for(int j=0;j<s.size();j++){
			for (int k = 0; k + j - 1 < s.size(); k++) {
				if ((s.substr(0, i) == t.substr(j, k) && s.substr(i, s.size() - i + 1) == t.substr(0, j))||s==t) {
					cout << "Yes" << endl;
					getchar();
					getchar();
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
	getchar();
	getchar();
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (S.at(i) != S.at(i - 1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512