akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
pair <int, int> L[200005];
int T;
int DP[200005][65];
void Read(){
    cin >> N >> T;
    for(int i = 1; i <= N; i++){
        cin >> L[i].first >> L[i].second;
    }
}

inline bool cmp(pair <int, int> a, pair <int, int> b){
    if(a.first == 0 && b.first == 0)
        return a.second < b.second;
    return (1LL * a.first * (b.second + 1)) > (1LL * b.first * (a.second + 1));
}

void Solve(){
    sort(L + 1, L + N + 1, cmp);
    int ans = 0;
    int point = N + 1;
    for(int j = 0; j <= 60; j++){
        for(int i = 0; i <= N; i++)
            DP[i][j] = T + 1;
    }
    DP[0][0] = 0;
    for(int i = 1; i <= N; i++){
        if(L[i].first == 0){
            point = i;
            break;
        }
        DP[i][0] = 0;
        for(int j = 1; j <= 60; j++){
            DP[i][j] = DP[i - 1][j];
            if(DP[i - 1][j - 1] <= T){
                long long aux = DP[i - 1][j - 1] + 1 + (1LL * L[i].first * (DP[i - 1][j - 1] + 1) + L[i].second);
                aux = min(aux, (1LL * (T + 1)));
                DP[i][j] = min(DP[i][j], (int)aux);
            }
        }
    }
    for(int j = 0; j <= 60; j++){
        int val = DP[point - 1][j], cnt = j;
        if(val == T + 1)
            continue;
        for(int k = point; k <= N; k++){
            if(val + L[k].second + 1 > T){
                break;
            }
            val += L[k].second + 1;
            cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
}


int main()
{
    Read();
    Solve();
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
#define fr first
#define sc second
#define mp1(a,b,c) P1(a,P(b,c))
ll INF=10000000000;

int main(){
	static int n;
	static int x[200010],y[200010];
	static char c[200010];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d %c",&x[i],&y[i],&c[i]);
	}
	
	ll ret=INF;
	
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='R'||c[i]=='U')vec.push_back(mp1(x[i]+y[i],x[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='R'&&c[vec[i+1].sc.sc]=='U')ret=min(ret,(vec[i+1].sc.fr-vec[i].sc.fr)*2);
		}
	}
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='D'||c[i]=='L')vec.push_back(mp1(x[i]+y[i],x[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='D'&&c[vec[i+1].sc.sc]=='L')ret=min(ret,(vec[i+1].sc.fr-vec[i].sc.fr)*2);
		}
	}
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='R'||c[i]=='D')vec.push_back(mp1(x[i]-y[i],x[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='R'&&c[vec[i+1].sc.sc]=='D')ret=min(ret,(vec[i+1].sc.fr-vec[i].sc.fr)*2);
		}
	}
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='U'||c[i]=='L')vec.push_back(mp1(x[i]-y[i],x[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='U'&&c[vec[i+1].sc.sc]=='L')ret=min(ret,(vec[i+1].sc.fr-vec[i].sc.fr)*2);
		}
	}
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='U'||c[i]=='D')vec.push_back(mp1(x[i],y[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='U'&&c[vec[i+1].sc.sc]=='D')ret=min(ret,vec[i+1].sc.fr-vec[i].sc.fr);
		}
	}
	if(1){
		vector<P1> vec;
		for(int i=0;i<n;i++){
			if(c[i]=='R'||c[i]=='L')vec.push_back(mp1(y[i],x[i],i));
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i+1<vec.size();i++){
			if(vec[i].fr==vec[i+1].fr&&c[vec[i].sc.sc]=='R'&&c[vec[i+1].sc.sc]=='L')ret=min(ret,vec[i+1].sc.fr-vec[i].sc.fr);
		}
	}
	if(ret==INF)puts("SAFE");
	else cout<<ret*5<<endl;
}

Measured memory_bytes: 15748
#include<stdio.h>
int main()
{
    int x,y,a,b,c;
    scanf("%d%d",&x,&y);
if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
{
    printf("Yes");
}
else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)){
    printf("Yes\n");
}
else{
    printf("No\n");
}
    return 0;
}

Measured memory_bytes: 128
l = list(map(int, input().split()))
l.sort()
c = l[-1]
a = l[0]
b = l[1]
if (a + b) % 2 == 0:
    print((2 * c - (a + b))//2)
else:
    print((2*(c+1)-(a+b+1))//2 + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007



bool is_Leap(int n){
	if(n%400==0)return true;
	if(n%100==0)return false;
	if(n%4==0)return true;
	return false;
}


int main(){
	int a,b;
	bool f=false;
	while(cin>>a>>b){
		if(a==0&&b==0)break;
		if(f)cout<<endl;
		else f=true;
		vi v;
		for(int i=a; i<=b; i++){
			if(is_Leap(i))v.pb(i);
		}
		if(v.empty())cout<<"NA"<<endl;
		else{
			rep(i,v.size()){
				cout<<v[i]<<endl;
			}
		}
	}
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,h,w,i,j,d,a[501][501];
ll ans;
int main(){
	scanf("%d%d%d%d",&n,&m,&h,&w);
	d=(1-h*w)*1000-1;
	for(i=1;i<=n;i++)
	 for(j=1;j<=m;j++){
	  if(i%h==0&&j%w==0)a[i][j]=d;
	  else a[i][j]=1000;
	  ans+=a[i][j];
  }
  if(ans<=0)return puts("No"),0;
  puts("Yes");
  for(i=1;i<=n;i++,puts(""))
   for(j=1;j<=m;j++)printf("%d ",a[i][j]);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<vector<int>> d(10, vector<int>(10, 0));
  int digit = 1;
  repz(i, 1, n + 1) {
    int right = i % 10;
    int left = i / digit;
    if (left >= 10) {
      digit *= 10;
      left /= 10;
    };
    d[left][right]++;
    // debug(i, left, right);
  }
  ll res = 0;
  repz(i, 1, 10) {
    repz(j, i, 10) {
      // debug(i, j, d[i][j] * d[j][i]);
      if (i == j)
        res += d[i][j] * d[j][i];
      else
        res += d[i][j] * d[j][i] * 2;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/agc007/tasks/agc007_a
fn main() {
    let (h, w) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut a = Vec::new();
    for _ in 0..h {
        let i = read_one::<String>().chars().collect::<Vec<char>>();
        a.push(i);
    }

    let mut x = 0;
    let mut y = 0;
    let mut flg = true;
    for i in 0..h { for j in 0..w {
        if a[i][j] == '#' {
            if !(y <= i && x <= j) { flg = false; }
            x = j; y = i;
        }
    }}
    if flg { println!("Possible"); }
    else { println!("Impossible"); }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define ll long long 
int main()
{
	ll ret = 0;

	int n;
	cin >> n;

	{
		int b;
		cin >> b;
		ret += b;
		int pre = b;

		for (int i = 1; i < n - 1; ++i) {
			cin >> b;
			if (pre < b) {
				ret += pre;
			}
			else {
				ret += b;
			}
			pre = b;
		}
		ret += b;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
ans = 1
if s[0] != "A":
    ans *= 0
if not (97 <= ord(s[1]) <= 122):
    ans *= 0
if not (97 <= ord(s[-1]) <= 122):
    ans *= 0

check = 0
for i in range(1, n - 1):
    if s[i] == "C":
        check += 1
print(["WA", "AC"][ans & (check == 1)])


Measured memory_bytes: 9128
#include <algorithm>
#include <cstdio>
using ll = long long;
constexpr ll sum = 1e10 + 19;
struct point
{
	ll x, y;
	inline point operator +(const point &a) const { return {x + a.x, y + a.y}; }
	inline point operator -(const point &a) const { return {x - a.x, y - a.y}; }
	inline ll operator *(const point &a) const { return x * a.y - y * a.x; }
};
inline ll calc_cnt(ll p, ll lim)
{
	ll q = sum - p, res = 0;
	if (p > q)
		std::swap(p, q);
	for (int y = 0; y * q <= lim; y++)
		res += (lim - y * q) / p + 1;
	return res;
}
inline point calc_sum(ll p, ll lim, int rem)
{
	rem -= calc_cnt(p, lim);
	ll q = sum - p;
	point res = {0, 0};
	bool rev = p > q;
	if (rev)
		std::swap(p, q);
	for (int y = 0; y * q <= lim; y++)
	{
		ll mx_x = (lim - y * q) / p;
		res = res + (point) {mx_x * (mx_x + 1) / 2, y * (mx_x + 1)};
		if (rem && !((lim + 1 - y * q) % p))
		{
			res = res + (point) {(lim + 1 - y * q) / p, y};
			rem--;
		}
	}
	if (rev)
		std::swap(res.x, res.y);
	return res;
}
inline ll search(ll p, int k)
{
	ll l = 0, r = sum * 2000, res = -1;
	while (l <= r)
	{
		ll mid = l + r >> 1;
		if (calc_cnt(p, mid) <= k)
		{
			res = mid;
			l = mid + 1;
		}
		else
			r = mid - 1;
	}
	return res;
}
inline bool check(int n, int m, int k)
{
	auto calc = [&] (ll p) { return calc_sum(p, search(p, k), k); };
	ll l = 0, r = sum;
	while (l + 1 < r)
	{
		ll mid = l + r >> 1;
		point res = calc(mid);
		if (res.x <= n && res.y <= m)
			return true;
		else if (res.x <= n)
			r = mid;
		else if (res.y <= m)
			l = mid;
		else
			return false;
	}
	point res_l = calc(l), res_r = calc(r);
	return (res_r - res_l) * ((point) {n, m} - res_l) <= 0;
}
int main()
{
	// freopen("D.in", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int l = 1, r = 4e6, ans = -1;
	while (l <= r)
	{
		int mid = l + r >> 1;
		if (check(n, m, mid))
		{
			ans = mid;
			l = mid + 1;
		}
		else
			r = mid - 1;
	}
	printf("%d\n", ans - 1);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        long[] a = new long[n + 1];
        long max =0;
        long ne =1;
        long ans = 0;

        for(int i=0;i<=n;i++){
            a[i]=scn.nextLong();
            max += a[i];
        }
        if(max==0){
            ne=-1;
        }

        for(int j=0;j<=n&&ne>=0;j++){
            ans+=ne;
            max=max-a[j];
            ne=(ne-a[j])*2;
            if(ne>max){
                ne=max;
            }
        }
        if(ne<0){
            ans=-1;
        }

        System.out.println(ans);

        scn.close();


    }


}

Measured memory_bytes: 49816
#include <cstdio>
#include <cstdlib>
#include <stack>

int main(){
    std::stack<int> st;
    char s[10];
    int op1,op2;

    while(scanf("%s",s)!=EOF){
        switch(s[0]){
        case '+':
            op2 = st.top();
            st.pop();
            op1 = st.top();
            st.pop();
            st.push(op1+op2);
            break;
        case '-':
            op2 = st.top();
            st.pop();
            op1 = st.top();
            st.pop();
            st.push(op1-op2);
            break;
        case '*':
            op2 = st.top();
            st.pop();
            op1 = st.top();
            st.pop();
            st.push(op1*op2);
            break;
        default:
            st.push(atoi(s));
            break;
        }
    }

    printf("%d\n",st.top());

    return 0;
}



Measured memory_bytes: 2752
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n;
vector<vector<long long> > memo2;

long long solve2(int pos, int rest)
{
    if(rest == 0)
        return 1;
    if(pos >= n)
        return 0;
    if(memo2[pos][rest] != -1)
        return memo2[pos][rest];

    long long ret = 0;
    for(int i=pos; i<=n-2; ++i)
        ret += solve2(i+2, rest - 1) * rest;

    return memo2[pos][rest] = ret;
}

vector<vector<vector<long long> > > memo;

long long solve(int pos, int rest, int isFirstHalf)
{
    if(rest == 0)
        return 1;
    if(pos >= n/2)
        return 0;
    if(memo[pos][rest][isFirstHalf] != -1)
        return memo[pos][rest][isFirstHalf];

    long long ret = 0;
    for(int i=pos; i<n/2; ++i){
        if(i == n/2-1){
            if(i == pos){
                if(!isFirstHalf)
                    ret += solve(i+1, rest-1, 1) * rest;
            }else{
                ret += solve(i+1, rest-1, 1) * rest;
            }
        }else if(i == pos){
            ret += solve(i+1, rest-1, isFirstHalf^1) * rest;
        }else{
            ret += solve(i+1, rest-1, 0) * rest;
            ret += solve(i+1, rest-1, 1) * rest;
        }
    }

    return memo[pos][rest][isFirstHalf] = ret;
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        if(n % 2 == 1){
            memo2.assign(n, vector<long long>(8, -1));
            long long ret = solve2(2, 7) * n;
            cout << ret << endl;
        }else{
            memo.assign(n/2, vector<vector<long long> >(8, vector<long long>(2, -1)));
            long long ret = solve(1, 7, 1) * n;
            cout << ret << endl;
        }
    }
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    std::vector<int> dp(n + 1);
    for (int i = 0; i < n; i++) {
        dp[i + 1] = std::max(dp[i + 1], dp[i]);
        if (s[i] == '1') continue;
        if (!(i > 0 && i + 1 < n && s[i - 1] == '1' && s[i + 1] == '1')) continue;
        for (int j = i - 1; j >= 0 && s[j] == '1'; j--) {
            dp[i + 2] = std::max(dp[i + 2], dp[j] + i - j);
        }
        for (int j = i + 1; j < n && s[j] == '1'; j++) {
            dp[j + 1] = std::max(dp[j + 1], dp[i - 1] + j - i);
        }
    }
    std::cout << dp[n] << std::endl;

    return 0;
}


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

int main() {
  int N,X;
  cin >> N >> X;
  vector<int> m(N+1);
  for(int i=0;i<N;i++) cin >> m.at(i);
  int ans=0;
  int sum_m=0;
  for(int i=0;i<N;i++){
    sum_m+=m.at(i);
    ans++;
  }
  int min=m.at(0);
  for(int i=0;i<N;i++){
    if(m.at(i)<min) min=m.at(i);
  }
  X-=sum_m;
  ans+=X/min;
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
W, H, N = map(int, input().split())
colors = np.ones((W, H), np.int)
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        colors[:x, :] = 0
    elif a == 2:
        colors[x:, :] = 0
    elif a == 3:
        colors[:, :y] = 0
    elif a == 4:
        colors[:, y:] = 0
ans = colors.sum()
# print(colors)
print(ans)


Measured memory_bytes: 12488
#include <stdio.h>
#include <math.h>
int main (void)
{
  int n, a, i, max, min;
  long sum;
  max = -10000000;
  min = 10000000;
  sum = 0;
  scanf("%d", &n);

  for(i =1; i<= n; i++)
  {
    scanf("%d", &a);
    if(a < min)
    {
      min = a;
    }
    if(a > max)
    {
      max = a;
    }
    sum = sum + a;
  }

  printf("%d %d %ld\n", min, max, sum);

  return 0;
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=2e5+5;
int dist[200005];
int inf=1e18;
int arr[N];
    int n;

#define float long double
#define vi vector<int>
// count of every prime factor 
int fuck(int n)
{
    float y=(-1+sqrt((1+8*n)))/(2);
    return (int) y;

}
vi factorize(long long n) 
{ 
    vi ans;
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        {
            ans.pb(2);
            ans.pb(count);
        }
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            {
                ans.pb(i);
                ans.pb(count);
            } 
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        ans.pb(n);
    return ans; 
} 
  
// driver program to test the above function 
signed main()
{
    cin>>n;
    int ans1=0;
    vi ans=factorize(n);
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
    {

        int y=ans[i];
        if (y==1) continue;
        int cnt=0;
        while((n%y==0))
        {
            n/=y;
            cnt++;
          //  cout<<"lol";
        }
        ans1+=fuck(cnt);
    }
    cout<<ans1;
}



Measured memory_bytes: 3720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace abc120_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var s = ConsoleInput.Read();
      var sLength = s.Length;

      var zero = 0;
      var one = 0;

      foreach (var c in s)
      {
        switch (c)
        {
          case '0':
            zero++;
            break;
          case '1':
            one++;
            break;
        }
      }

      Console.WriteLine(sLength - Math.Abs(zero - one));
    }
  }

  class ConsoleInput
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadAsInt() => int.Parse(Read());
    public static long ReadAsLong() => long.Parse(Read());
    public static double ReadAsDouble() => double.Parse(Read());

    public static string[] ReadAsStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadAsIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsInt();
      }

      return array;
    }

    public static long[] ReadAsLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsLong();
      }

      return array;
    }
    public static double[] ReadAsDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 13304
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
char tmp[maxn];
string s;

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

void solve() {
  vector<char> st;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'T' && sz(st) >= 1 && st.back() == 'S') {
      st.pop_back();
    } else {
      st.push_back(s[i]);
    }
  }
  printf("%d\n", sz(st));
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<unsigned long, unsigned long>> cards(N);
    for(auto& i : cards)cin >> i.first;
    for(auto& i : cards)cin >> i.second;
    constexpr unsigned long even = numeric_limits<unsigned long>::max() / 3;
    constexpr unsigned long odd = even * 2;
    unsigned long ans{numeric_limits<unsigned long>::max()};
    for(unsigned long i{0}; i < 1UL << N; ++i){
        if(__builtin_popcountl(i & even) != __builtin_popcountl(i & odd))continue;
        vector<pair<unsigned long, unsigned long>> odds, evens;
        for(unsigned long j{0}; j < N; ++j){
            auto t = ((i >> j) & 1) ? cards[j].second : cards[j].first;
            if((j ^ (i >> j)) & 1)odds.emplace_back(t, j);
            else evens.emplace_back(t, j);
        }
        sort(odds.begin(), odds.end());
        sort(evens.begin(), evens.end());
        [&]{for(unsigned long j{0}; j < odds.size(); ++j)if(odds[j].first < evens[j].first)return;
            for(unsigned long j{1}; j < evens.size(); ++j)if(odds[j - 1].first > evens[j].first)return;
            vector<unsigned long> indexes(N);
            for(unsigned long j{0}; j < odds.size(); ++j)indexes[odds[j].second] = 2 * j + 1;
            for(unsigned long j{0}; j < evens.size(); ++j)indexes[evens[j].second] = 2 * j;
            unsigned long cnt{0};
            for(unsigned long j{1}; j < N; ++j)for(unsigned long k{0}; k < j; ++k)if(indexes[k] > indexes[j])++cnt;
            ans = min(ans, cnt);
        }();
    }
    cout << static_cast<long>(ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c==17 && a*b*c==175)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;	

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type& a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	vi cnte(n,0),cntw(n,0);
	for(int i=1;i<n;++i){
		if(s[i-1]=='W') cntw[i]=cntw[i-1]+1;
		else cntw[i]=cntw[i-1];
	}
	for(int i=n-2;i>=0;--i){
		if(s[i+1]=='E') cnte[i]=cnte[i+1]+1;
		else cnte[i]=cnte[i+1];
	}
	//join(cntw);join(cnte);//!!!!!!!!!!!!!	
	
	int ans=INF;
	REP(i,n) ans=min(ans,cntw[i]+cnte[i]);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 1e2+10;
const int MAX_W = 1e4+10;

struct Item
{
	int v, w;
};

int N, W;
int dp[MAX_N][MAX_W];
Item items[MAX_N];

void solve() {
	for (int i = 0; i < N; ++i) {
		Item item = items[i];
		for (int w = 0; w <= W; ++w) {
			if (w < item.w) {
				dp[i+1][w] = dp[i][w];
			}
			else {
				dp[i+1][w] = max(dp[i][w], dp[i][w-item.w] + item.v);
			}
		}
	}
}


int main(int argc, char const *argv[])
{
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> items[i].v >> items[i].w;
	}

	solve();

	cout << dp[N][W] << endl;
	return 0;
}


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

int main()
{
	int nInput[3] = { 0 };
	for (size_t i = 0; i < 3; i++)
	{
		cin >> nInput[i];
	}

	for (size_t i = 0; i < 2; i++)
	{
		for (size_t j = 0; j < 2 - i; j++)
		{
			int nTemp = 0;
			if (nInput[j] > nInput[j + 1])
			{
				nTemp = nInput[j];
				nInput[j] = nInput[j + 1];
				nInput[j + 1] = nTemp;
			}
		}
	}
	cout << nInput[0] << " " << nInput[1] << " " << nInput[2] << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll a[20];

ll dfs(int l,int r,int lx,int rx){
	if(l+1==r) return 0;
	ll ans=1e18;
	for(int i=l+1;i<r;i++) ans=min(ans,dfs(l,i,lx,lx+rx)+dfs(i,r,lx+rx,rx)+1ll*(lx+rx)*a[i]);
	return ans;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		double c = 100000;
		for(int i = 0; i < n; i++) {
			c += c*0.05;
			if(c % 1000 != 0) {
				c -= c % 1000;
				c += 1000;
			}
			
		}
		System.out.printf("%.0f\n",c);
	}
}

Measured memory_bytes: 17172
#include<cstdio>
int main(){
    bool ar[3];
    ar[0]=true;
    ar[1]=ar[2]=false;
    char a,b;
    while(scanf("%c,%c\n",&a,&b)!=-1){
        bool t=ar[b-'A'];
        ar[b-'A']=ar[a-'A'];
        ar[a-'A']=t;
    }
    for(int i=0;i<3;i++){
        if(ar[i])printf("%c\n",(char)('A'+i));
    }
}

Measured memory_bytes: 0
from math import *
n=int(input())
mi,mx=0,n-1
print(mi)
t1=input()
if t1=="Vacant":
    exit()
print(mx)
t2=input()
if t2=="Vacant":
    exit()
while True:
    mid=ceil((mi+mx)/2)
    print(mid)
    t2=input()
    if t2=="Vacant":
        exit()
    sa=mid-mi
    if sa%2==0:
        if t1==t2:
            mi=mid
            t1=t2
        else:
            mx=mid
    else:
        if t1==t2:
            mx=mid
        else:
            mi=mid
            t1=t2

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

using namespace std;

int main(){
    int n;
    cin>>n;
    double ans=0.0;
    for(int i=0;i<n;i++){
        double x;
        string s;
        cin>>x>>s;
        if(s=="BTC")
            ans += x * 380000.0;
        else
            ans += x;
    }
    cout<<ans;
}


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

int main() {
    ll l, r;
    cin >> l >> r;
    r = min(r, l+4038);
    int ans = 2018;
    for (ll i = l; i <= r; i++) {
        for (ll j = i+1; j <= r; j++) {
            int x = i*j%2019;
            ans = min(ans, x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass {
  public static void Main (string[] args) {
    //入力
    var N = long.Parse(Console.ReadLine());
    var list = new List<int>();
    var A = (long)1;
    var B = (long)1;
    while(A <= B && A * A <= N){
      if(N % A == 0){
        B = N / A;
        list.Add(Math.Max(A, B).ToString().Length);
      }
      A++;
    }
    Console.WriteLine(list.Min());
    
  }
}

Measured memory_bytes: 13268
fun main(arr: Array<String>) {
    println(if(getAns()) "Possible" else "Impossible")
}

fun getAns():Boolean {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!!.toMutableList() }
    if(map[0][0] != '#' || map.last().last() != '#') {
        return false
    }
    map[0][0] = '*'
    var x = 0
    var y = 0
    while (x != map.last().lastIndex || y != map.lastIndex) {
        var nextX = x
        var nextY = y
        var cnt = 0
        map[y][x] = '*'
        for(i in (y-1..y+1)) {
            if(i < 0 || i >= h) {
                continue
            }
            for(j in (x-1..x+1)) {
                if(j < 0 || j >= w) {
                    continue
                }
                if(i != y && j != x) {
                    continue
                }
                if(map[i][j] != '#') {
                    continue
                }
                nextY = i
                nextX = j
                cnt++
            }
        }
        if(cnt != 1) {
            return false
        }
        if(nextY < y) {
            return false
        }
        if(nextX < x) {
            return false
        }
        y = nextY
        x = nextX
    }
    if(map.sumBy { it.count { it=='#' } } > 1) {
        return false
    }
    return true
}

Measured memory_bytes: 36640
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int a, b;
	cin >> a >> b;
	int ans = a + b / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int r,g,b,temp1,temp2,total;
    scanf("%d",&r);
    scanf("%d",&g);
    scanf("%d",&b);

    temp1=r*100;
    temp2=g*10;
    total=(temp1+temp2+b);

    if(total%4==0){
        printf("YES");
    }
    else{
            printf("NO");

    }
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

int par[1010];
int last[100];
map<string, int> name;

bool check_ancestor(int a, int d){
	if (a < 0 || d < 0) return false;
	if (a == par[d]) return true;
	return check_ancestor(a, par[d]);
}

int main(){
	int n, q;
	while (cin >> n >> q, n|q){
		name.clear();
		MEMSET(last, -1);
		MEMSET(par, -1);
		cin.ignore();
		rep(i, n){
			string s;
			getline(cin, s);
			int cnt = count(ALL(s), ' ');
			last[cnt] = i;
			name[s.substr(cnt)] = i;
			if (!cnt) continue;
			par[i] = last[cnt - 1];
		}
		while (q--){
			string a, b, c, d, e, f;
			cin >> a >> b >> c >> d >> e >> f;
			//cout << f.substr(0, f.size() - 1) << endl;
			int x = name[a], y = name[f.substr(0, f.size() - 1)];
			bool ok;
			switch (d[0]){
			case 'c':
				ok = par[x] == y;
				break;
			case 'a':
				ok = check_ancestor(x, y);
				break;
			case 's':
				ok = par[x] == par[y];
				break;
			case 'p':
				ok = x == par[y];
				break;
			case 'd':
				ok = check_ancestor(y, x);
			}
			cout << (ok ? "True" : "False") << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
  vector<vector<int> >dp(100001,vector<int>(4,-1));
  int solve(vector<int>&a,vector<int>&b,vector<int>&c,int i,int p){
      if(i==a.size()) return 0;
      if(dp[i][p]!=-1) return dp[i][p];
      int h=0;
      if(p!=1){
          h=max(h,solve(a,b,c,i+1,1)+a[i]);
      }
      if(p!=2){
          h=max(h,solve(a,b,c,i+1,2)+b[i]);
      }
      if(p!=3){
          h=max(h,solve(a,b,c,i+1,3)+c[i]);
      }
      dp[i][p]=h;
      return h;
  }




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<solve(a,b,c,0,0)<<endl;
    
   
   
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(double (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    double n, m, d;
    cin >> n >> m >> d;
    cout << (d ? 2 * (n - d) / pow(n, 2) : 1 / n) * (m - 1) << "\n";
}

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

int main() {
  int64 r, d, x;
  cin >> r >> d >> x;
  for (int i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 998244353
ll ans[500010]={};
int main() {
	ll n,k;
	cin>>n>>k;
	ans[1]=1;
	ll l[12],r[12];
	for(ll i=0;i<k;i++){
		cin>>l[i]>>r[i];
		r[i]++;
	}
	ll cnt=0;
	for(ll i=1;i<=n;i++){
		cnt+=ans[i];
		cnt%=inf;
		if(cnt<0){
			cnt+=inf;
		}
		for(ll j=0;j<k;j++){
			ans[i+l[j]]+=cnt;
			ans[i+l[j]]%=inf;
			ans[i+r[j]]-=cnt;
			if(ans[i+r[j]]<0){
				ans[i+r[j]]+=inf;
			}
		}
	}
	cout << ans[n];
	// your code goes here
	return 0;
}

Measured memory_bytes: 6716
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
B=int(s*K+(S*K*(K-1))//2)
C=int(s*K)%1000000007
D=(K*(K-1)//2)%1000000007
print((C+S*D)%1000000007)

Measured memory_bytes: 40812
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.second == b.second)
    return a.first > b.first;
  return a.second > b.second;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vector<pll> C(N);

  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    C[i] = make_pair(a, b);
  }
  sort(ALL(C));

  priority_queue<pll> D;
  ll ans = 0;

  ll now = 0;
  RREP(j, M) {
    FOR(i, now, N) {
      if (C[i].first + j > M)
        break;
      D.push(make_pair(C[i].second, C[i].first));
      now++;
    }
    if (D.size() > 0) {
      pll po = D.top();
      ans += po.first;
      D.pop();
    }
  }

  /*REP(i, now) {
    pll po = D.top();
    D.pop();
    cout << po.first << "," << po.second << endl;
  }*/
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3956
/*
    Problem 32
    https://onlinejudge.u-aizu.ac.jp/problems/1166
*/
#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 = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<int> dx{0, 0, 1, -1}, dy{1, -1, 0, 0};
/* function */
void solve(int h, int w) {
    int H = 2*h - 1, W = 2*w - 1;
    vector<vector<int>> G(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++)
        for (int j = (i%2 == 0); j < W; j+=2)
            cin >> G[i][j];
    int sx = 0, sy = 0, gx = H-1, gy = W - 1;
    queue<pii> q;
    vector<vector<int>> dist(H, vector<int>(W, 0));
    dist[sx][sy] = 1;
    q.emplace(sx, sy);

    while (!q.empty()) {
        pii p = q.front();
        q.pop();
        int x = p.first, y = p.second;
        for (int i = 0; i < dx.size(); i++) {
            int nx = x + dx[i], ny = y + dy[i];
            int nnx = x + 2 * dx[i], nny = y + 2 * dy[i];
            if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
            if (G[nx][ny] || G[nnx][nny]) continue;
            if (dist[nnx][nny] != 0) continue;
            dist[nnx][nny] = dist[x][y] + 1;
            q.emplace(nnx, nny);
        }
    }
    cout << dist[gx][gy] << '\n';
}
/* main */
int main(){
    int h, w;
    while (1) {
        cin >> w >> h;
        if (w == 0) return 0;
        solve(h, w);
    }
}


Measured memory_bytes: 3052
class D_Linked_List:
    class Node:
        def __init__(self, key, next = None, prev = None):
            self.next = next
            self.prev = prev
            self.key = key

    def __init__(self):
        self.nil = D_Linked_List.Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil

    def insert(self, key):
        node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
        self.nil.next.prev = node_x
        self.nil.next = node_x

    def _listSearch(self, key):
        cur_node = self.nil.next
        while (cur_node != self.nil) and (cur_node.key != key):
            cur_node = cur_node.next
        return cur_node

    def _deleteNode(self, node):
        if node == self.nil:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._deleteNode(self.nil.next)

    def deleteLast(self):
        self._deleteNode(self.nil.prev)

    def deleteKey(self, key):
        node = self._listSearch(key)
        self._deleteNode(node)

    def show_keys(self):
        cur_node = self.nil.next
        keys = []
        while cur_node != self.nil:
            keys.append(cur_node.key)
            cur_node = cur_node.next
        print(' '.join(map(str, keys)))


import sys

d_ll = D_Linked_List()

for i in sys.stdin:
    if 'insert' in i:
        x = int(i.split()[1])
        d_ll.insert(x)
    elif 'deleteFirst' in i:
        d_ll.deleteFirst()
    elif 'deleteLast' in i:
        d_ll.deleteLast()
    elif 'delete' in i:
        x = int(i.split()[1])
        d_ll.deleteKey(x)
    else:
        pass

d_ll.show_keys()

Measured memory_bytes: 205336
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

char map[100][100];

char countbomb(int x, int y) {
	int value = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (!(i == 0 && j == 0)) {
				if (map[x + i][y + j] == '#')value++;
			}
		}
	}
	char ans = '0' + value;
	return ans;
}

int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i <= 99; i++) {
		for (int j = 0; j <= 99; j++)map[i][j] = '.';
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++)cin >> map[i][j];
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (map[i][j] == '.')map[i][j] = countbomb(i, j);
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << map[i][j];
		}
		cout << 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 rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define ln << "\n"

const int inf = (int)1e9;
int n, m, c[21], dp[21][50001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	repst(i,1,m) cin >> c[i];
	rept(i,m) fill(dp[i], dp[i]+n+1, inf);
	dp[0][0] = 0;
	repst(i,1,m) {
		rept(j,n) {
			if (j<c[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
		}
	}
	cout << dp[m][n] ln;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d.at(i);
    }
    int m;
    cin >> m;
    vector<int> t(m);
    for(int i=0; i<m; i++){
        cin >> t.at(i);
    }

    sort(d.begin(),d.end());
    sort(t.begin(),t.end());

    int i=0,j=0;
    while(1){
        if(j==m){
            cout << "YES" << endl;
            break;
        }
        if(i==n){
            cout << "NO" << endl;
            break;
        }
        if(d.at(i)==t.at(j)) j++;
        i++;
    }
}

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

int main(){
    int x;
    cin >> x;
    int max = 0;
    if(x==1){
        cout << x << endl;
    }else{
    for(int i=1;i<x;i++){
        int a=i;
        for(int j=0;j<x;j++){
            a*=i;
            if(a>x){
                break;
            }else if(max<a){
                max = a;
            }
        }
    }
    cout << max << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();    
    
    boolean continueFlg = true;
    if (x==2) {
      continueFlg = false;
    }
    while (continueFlg) {
      for (int i=2; i<x; i++) {
        if (x%i==0) {
          break;
        }
        if (i==x-1) {
          continueFlg = false;
        }
      }
      if (continueFlg) {
        x++;
      }
    }
    System.out.println(x);
    
  } 
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
//#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <stack>
//#include <queue>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using namespace std;

#define MAXN 1000

int main() {
	const int M = 31;

	int n;
	cin >> n;
	int u[MAXN + 1], v[MAXN + 1];
	bool is_even;
	int m = 1;
	REP1(i_point, n) {
		int x, y;
		cin >> x >> y;
		if (i_point == 1) {
			is_even = ((x + y) % 2 == 0);
		}
		else {
			if (is_even != ((x + y) % 2 == 0)) {
				cout << -1 << endl;
				return 0;
			}
		}
		u[i_point] = x + y;
		v[i_point] = x - y;
		if (is_even) {
			u[i_point]--;
			v[i_point]--;
		}
		for (int k = 1; k <= M; k++) {
			const ll tptk = (ll)1 << k;
			if ((-tptk < u[i_point] && u[i_point] < tptk && -tptk < v[i_point] && v[i_point] < tptk)) {
				m = max(m, k); 
				break;
			}
		}
	}

	const int maxu = (1 << m) - 1;
	int m_ans = m;
	if (is_even)
		m_ans++;
	cout << m_ans << endl;
	REP(j_arm, m) {
		cout << (1 << j_arm) << " ";
	}
	if (is_even) {
		cout << 1;
	}
	cout << endl;
	REP1(i_point, n) {
		unsigned int tmpu = (u[i_point] + maxu) / 2;
		unsigned int tmpv = (v[i_point] + maxu) / 2;
		REP(j_arm, m) {
			char c;
			if ((tmpu & 1) == 1) {
				if ((tmpv & 1) == 1) {
					c = 'R';
				}
				else {
					c = 'U';
				}
			}
			else {
				if ((tmpv & 1) == 1) {
					c = 'D';
				}
				else {
					c = 'L';
				}
			}
			cout << c;
			tmpu >>= 1;
			tmpv >>= 1;
		}
		if (is_even) {
			cout << 'R';
		}
		cout << endl;
	}

	return 0;
}

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

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

    int n;
    cin >> n;

    long long x, y, a = 1, b = 1;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        
        // WA
        long long p = max((a + (x - 1)) / x, (b + (y - 1)) / y);
        a = x * p;
        b = y * p;
        
        continue;

        long long p1 = a / x + (a % x ? 1 : 0);
        long long p2 = b / y + (b % y ? 1 : 0);

        a = x * max(p1, p2);
        b = y * max(p1, p2);
    }

    cout << a + b << endl;

    return 0;
}

Measured memory_bytes: 256