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

using namespace std;

#define sz(x) ((int) (x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long flow_t;
const flow_t flow_inf = 1e18;

struct edge {
	int v, u;
	flow_t c, f;
	edge(int v, int u, flow_t c): v(v), u(u), c(c), f(0) {}
};

struct Network {
	int n;
	int s, t;
	vector <edge> es;
	vector <vector <int> > g;
	Network(int n, int s, int t): n(n), s(s), t(t), g(n) {}

	void add_edge(int v, int u, flow_t c) {
		g[v].push_back(es.size());
		es.push_back(edge(v, u, c));
		g[u].push_back(es.size());
		es.push_back(edge(u, v, 0));
	}

	void add_flow(int e, flow_t f) {
		es[e].f += f;
		es[e ^ 1].f -= f;
	}
};

class DinicMaxFlow {
public:
	Network& G;

	int *pos, *d, *q;

	DinicMaxFlow(Network& G): G(G) {
		pos = new int[G.n];
		q = new int[G.n];
		d = new int[G.n];
	}
	~DinicMaxFlow() {
		delete[] pos;
		delete[] q;
		delete[] d;
	}

	int bfs() {
		const int MXD = G.n + 1;
		fill(d, d + G.n, MXD);
		d[G.s] = 0;
		q[0] = G.s;
		int l = 0, r = 1;
		while (l < r) {
			int v = q[l++];
			for (int e: G.g[v]) {
				if (G.es[e].c == G.es[e].f)
					continue;
				int u = G.es[e].u;
				if (d[u] == MXD) {
					d[u] = d[v] + 1;
					q[r++] = u; 
				}
			}
		}
		return d[G.t] < MXD;
	}

	flow_t dfs(int v, flow_t f) {
		if (v == G.t)
			return f;
		flow_t res = 0;
		for (int &i = pos[v]; i < sz(G.g[v]); ++i) {
			int e = G.g[v][i];
			int u = G.es[e].u;
			flow_t delta = min(f, G.es[e].c - G.es[e].f);
			if (delta == 0 || d[u] != d[v] + 1)
				continue;
			delta = dfs(u, delta);
			f -= delta;
			res += delta;
			G.add_flow(e, delta);
			if (f == 0)
				break;
		}
		return res;
	}



	flow_t max_flow() {
		flow_t flow = 0;
		while (bfs()) {
			fill(pos, pos + G.n, 0);
			while (flow_t plus = dfs(G.s, flow_inf))
				flow += plus;
		}
		return flow;
	}
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n;
    cin >> n;
    vector< pair<int, int> > a(n);
    vector< pair<int, int> > b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i].first >> b[i].second;
    }
    Network g(2 * n + 2, 0, 2 * n + 1);
    for (int i = 1; i <= n; ++i) {
        g.add_edge(g.s, i, 1);
        g.add_edge(i + n, g.t, 1);
        for (int j = 1; j <= n; ++j) {
            if (a[i - 1].first < b[j - 1].first && a[i - 1].second < b[j - 1].second) {
                g.add_edge(i, j + n, 1);
            }
        }
    }
    cout << DinicMaxFlow(g).max_flow() << '\n';
	  
    return 0;
}


Measured memory_bytes: 604
#include <iostream>
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i = 0; i < n1; i++) L[i] = A[left + i];
	for(i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;
	for(k=left; k < right; k++){
		if(L[i].value <= R[j].value){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right){
	int mid;
	if(left+1 < right){
		mid = (left + right) /2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[], int n, int p, int r){
	int i, j;
	struct Card t, x;
	x=A[r];
	i=p - 1;
	for(j=p; j<r; j++){
		if( A[j].value <= x.value ){
			i++;
			t=A[i]; A[i]=A[j]; A[j]=t;
		}
	}
	t=A[i+1]; A[i+1]=A[r]; A[r]=t;
	return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
	int q;
	if(p<r){
		q=partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q + 1, r);
	}
}

int main(){
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> S >> v;
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
	}
	
	mergeSort(A, n, 0, n);
	quickSort(B, n, 0, n-1);
	
	for(i = 0; i < n; i++){
		if(A[i].suit != B[i].suit) stable = 0;
	}
	
	if(stable == 1) {
	    cout << "Stable\n";
	} else{
	    cout << "Not stable\n";
	}
	for(i = 0; i < n; i++){
		cout << B[i].suit << " " << B[i].value << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 5324
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    C = Counter(a)
    for i in range(1, n + 1):
        if C[i]:
            print(C[i])
        else:
            print(0)

if __name__ == '__main__':
    main()


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

bool is_war(const vector<int>& x, const vector<int>& y){
  for(int Z = -100; Z <= 100; ++Z){
    bool is_ok =true;
    for(int i = 0; i < x.size(); ++i){
      if(x[i] >= Z) is_ok = false;
    }
    for(int i =0; i < y.size(); ++i){
      if(y[i] < Z) is_ok = false;
    }
    if(is_ok) return false;
  }
  return true;
}


int main()
{
  int N, M; cin >> N >> M;
  vector<int> x(N+1), y(M+1);
  cin >> x[0] >> y[0];
  for(int i = 0; i < N; ++i){
    cin >> x[i + 1];
  }
  for (int i = 0; i < M; ++i){
    cin >>y[i + 1];
  }
  if(is_war(x, y)){
    cout << "War" << endl;
  }
  else {
    cout << "No War" <<endl;
  }
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

N = getN()
for i in range(10**4):
    if i*(i+1)/2 >= N:
        M = i
        upper =int(M*(M+1)/2)
        break
tar = []
diff = upper-N
for i in range(M):
    j = i+1
    if j != diff:
        #tar.append(j)
        print(j)
"""
print(sum(tar),M,upper,diff)
if 1628 in tar:
    print("TRue")
"""

Measured memory_bytes: 3408
// finish date: 2018/06/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pii pair<int,int>
const int bigmod = 1000000007;
#define INF 1050000000


int main() {
    int N, C;
    cin >> N >> C;
    vvi D(C, vi(C));
    vvi c(N, vi(N));
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, C) rep(j, C) cin >> D[i][j];
    rep(i, N) {
        rep(j, N) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    vector<vector<pii>> amari(3, vector<pii >(C, pii(0, 0)));
    rep(k, C) {
        rep(i, N) {
            rep(j, N) {
                amari[(i + j) % 3][k] = pii(amari[(i + j) % 3][k].first + D[c[i][j]][k], k);
            }
        }
    }
    sort(amari[0].begin(), amari[0].end());
    sort(amari[1].begin(), amari[1].end());
    sort(amari[2].begin(), amari[2].end());
    int mi = INF;
    rep(i, 3) {
        rep(j, 3) {
            rep(k, 3) {
                if (amari[0][i].second != amari[1][j].second &&
                    amari[1][j].second != amari[2][k].second &&
                    amari[2][k].second != amari[0][i].second) {
                    mi = min(mi, amari[0][i].first + amari[1][j].first + amari[2][k].first);
                }
            }
        }
    }
    cout << mi << endl;

    return 0;
}






Measured memory_bytes: 1408
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(a - c) <= d || ( abs(a - b) <= d && abs(b - c) <= d ))
        cout << "Yes";
    else
        cout << "No";
    cout << endl;        

    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    ll p = 0;
    ll q = 0;
    VI v(n);
    for (i = 0; i < n; i++) {
        cin >> v[i];
        p += v[i];
        if (i % 2 == 1) q += v[i];
    }
    cout << p - 2 * q;
    VI x(n);
    x[0] = p - 2 * q;
    for (i = 0; i < n - 1; i++) {
        x[i + 1] = 2 * v[i] - x[i];
        cout << " " << x[i + 1];
    }
    cout << endl;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a >= b && a >= c) {
        cout << a*10 + b + c << endl;
    }else if(b >= a && b >= c) {
        cout << b*10 + a + c << endl;
    }else {
        cout << c*10 + a + b << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	int answer = 700;
	for (char c : s) {
		if (c == 'o') {
			answer += 100;
		}
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
    high = max(A)
else:
    low = 0
    high = 10**9
    while high-low>1:
        mid = (high+low)//2
        cnt = 0
        for i in range(N):
            if A[i]%mid==0:
                cnt += A[i]//mid-1
            else:
                cnt += A[i]//mid
        if K>=cnt:
            high = mid
        else:
            low = mid
print(high)

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

int main()
{
	int N,a=10000000000,b=0,t;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> t;
		if (a > t)a = t;
		if (b < t)b = t;
	}

	cout << abs(a - b) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int[]score = new int[N];
		
		for(int i = 0; i< N; i++) {
			score[i] = keyboard.nextInt();
		}
		Arrays.sort(score);
		int ans = 0;

		if(score[N/2] == score[N/2-1]) {
			ans = 0;
		}else{
			ans = score[N/2] - score[N/2-1];
		}

		System.out.print(ans);
		keyboard.close();	
	}
}


Measured memory_bytes: 50764
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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 h, w;
vector<string> s;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    rep(i, h)
    {
        rep(j, w)
        {
            int count = 0;
            if(s[i][j]=='#')continue;
            rep(k, 8)
            {
                if (i + Dx[k] < 0 || j + Dy[k] < 0 || i + Dx[k] >= h || j + Dy[k] >= w)
                    continue;
                if (s[i + Dx[k]][j + Dy[k]] == '#')
                    count++;
            }
            s[i][j]=count+'0';
        }
    }
    rep(i,h){
        cout<<s[i]<<"\n";
    }
}


Measured memory_bytes: 256
"use strict";

function main(arg) {
    const input = arg.split("\n")
    let N = Number(input[0])
    let A = input[1].split(" ").map(Number).sort((a,b)=>b-a)
    //console.log(A)
    
    let dp=[]// i人目入った時の心地よさ合計最大値
    for(let i=0; i<N; i++) {
        dp.push(0)
    }
    //dp[0] = A[0]
    //console.log(dp)
    
    //console.log(Math.min(dp))
    let min = 0
    for(let i=1; i<N; i++) {
        let id = 0
        if(i>=2) {
            //console.log(i/2)
            id = parseInt(i/2)
        }
        //console.log(id)
        dp[i]=dp[i-1]+A[id]
        //min = A[i]
    }
    //console.log(dp)
    console.log(dp[N-1])


}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 58104
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<int> mn(n);
  mn[0] = p[0];
  for (int i = 1; i < n; ++i) {
    mn[i] = min(mn[i - 1], p[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] <= mn[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4844
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(10);
  std::cerr << std::fixed << std::setprecision(6);

  long double n, m, d;

  std::cin >> n >> m >> d;

  std::cout << (n - d) * (d ? 2 : 1) * (m - 1) / n / n << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  ll a, b, x;
  cin >> a >> b >> x;
  ll e = b / x, s = (a - 1) / x;
  if (a == 0)
    s = -1;
  cout << e - s << endl;
}


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

ll N1, N2, N3;
set<ll> S;

signed main(){
    cin >> N1 >> N2 >> N3;
    S.insert(N1);
    S.insert(N2);
    S.insert(N3);
    if(S.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
string s;
ll k;
cin >> s >> k;
ll n = s.size();
map<string, ll> mp;
for (ll i = 0; i < n;i++){
    for (ll j=1; j <= min(n-i,k);j++){
        string tmp = s.substr(i, j);
        mp[tmp]++;
    }
}
string ans;
for (auto i : mp) {
    k--;
    if (k == 0) {
        ans = i.first;
        break;
    }
}
cout << ans << endl;
}

Measured memory_bytes: 1920
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			long[] a = new long[n];
			long[] b = new long[n];
			TreeMap<Long,Long> m = new TreeMap<Long,Long>();
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextLong();
				b[i] = sc.nextLong();
			}
			
			for(int i=0;i<n;i++) {
				m.merge(b[i], a[i], Long::sum);
			}
			
			long sum = 0;
			
			for(Map.Entry<Long, Long> e :m.entrySet()) {
				sum += e.getValue();
				if(e.getKey()<sum) {
					System.out.println("No");
					return;
				}
			}
			
			System.out.println("Yes");
	    }
		
	}
	


Measured memory_bytes: 73584
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(void){
	int n,m,i,j,k,r,b;
	char d[2][20],s[44];
	ll dp[20][20],ans=0ll;
	scanf("%d",&n);
	scanf("%s",s);
	m = (1<<n);
	for(i=0; i<m; ++i){
		r = 0; b = 0;
		for(j=0; j<n; ++j){
			if((i&(1<<j))){
				d[0][r] = s[j];
				++r;
			}else{
				d[1][b] = s[j];
				++b;
			}
		}
		fill(dp[0],dp[20],0ll);
		dp[r][b] = 1ll;
		for(j=r; j>=0; --j){
			for(k=b; k>=0; --k){
				if(j > 0 && s[n+j+k-1] == d[0][r-j]){
					dp[j-1][k] += dp[j][k];
				}
				if(k > 0 && s[n+j+k-1] == d[1][b-k]){
					dp[j][k-1] += dp[j][k];
				}
			}
		}
		ans += dp[0][0];
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> a(n+1,0);
  REP(i,m){
    int x;cin >> x;
    a[x]++;
  }
  int left = 0,right = 0;
  REP(i,x)left += a[i];
  for(int i = x;i <= n;i++)right += a[i];
  int res = min(left,right);
  cout << res << endl;

  return 0;
}


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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset ((a), v, sizeof (a))

using namespace std;

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

const int N = 100005;

int n;
int dat[N];

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", &dat[i]);
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (dat[i] == i) {
			swap (dat[i], dat[i + 1]);
			++ans;
		}
	}
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define WHITE 1
#define BLACK 0
#define NOCOLOR -1
#define DEBUG 0

using namespace std;

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

const int MAX_N = (int)1e5 + 5;

vector<int> G[MAX_N];

int path[MAX_N]; // path[to]:= from
int color[MAX_N]; // none: -1 black:0 white:1
int N;
int dfs(int curr, int prev, int depth){
	path[curr] = prev;

	if (curr == N - 1){
		return depth;
	} // end i
	
	int res = 0;
	for (int i = 0; i < (int)G[curr].size(); ++i){
		int next = G[curr][i];
		if (next == prev) continue;
		res = max(res, dfs(next, curr, depth + 1));
	} // end for

	return res;
}

int remain_black;
int remain_white;

void dfs2(int curr, int prev, int flag){

	if (color[curr] == NOCOLOR){
		remain_black += (flag == BLACK ? 1 : 0);
		remain_white += (flag == WHITE ? 1 : 0);
		color[curr] = (flag == BLACK ? BLACK : WHITE);
	} // end if

	for (int i = 0; i < (int)G[curr].size(); ++i){
		int next = G[curr][i];
		if (next == prev) continue;
		if (color[next] == NOCOLOR){
			dfs2(next, curr, flag);
		} // end if
	} // end for
}	  

int main()
{
	rep (i, MAX_N) G[i].clear();
	memset(path, -1, sizeof(path));
	memset(color, NOCOLOR, sizeof(color));

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	rep (i, N - 1){
		int a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	} // end if

	int len = dfs(0, -1, 0);	// 0 と N - 1 の最短距離
#if DEBUG
	cerr << "len: " << len << endl;
#endif
	int from = -1;
	int to = N - 1;
	color[0] = BLACK;
	color[N-1] = WHITE;

	for (int i = 0; i < len; ++i){
		if (i <= (len - 1) / 2){
			color[to] = WHITE;
		}else{
			color[to] = BLACK;
		} // end if
		from = path[to];
#if DEBUG
		cerr << "to: " << to << " from: " <<  from << endl;
#endif
		to = from;
	} // end for

	remain_black = 0;
	rep (i, N - 1){
		if (color[i] == BLACK){
			dfs2(i,-1, BLACK);
		} // end if
	} // end rep

	remain_white = 0;
	for (int i = N - 1; i > 0; --i){
		if (color[i] == WHITE){
			dfs2(i, -1, WHITE);
		} // end if
	} // end for
#if DEBUG
	cerr << "remain_black: " << remain_black << " remain_white: " << remain_white << endl;
#endif
	bool win = false;
	if (len % 2 == 0){
		if (remain_white <= remain_black){
			win = true;
		}else{
			win = false;
		} // end if
	}else{ // if (len % 2 == 0)
		if (remain_white < remain_black){
			win = true;
		}else{
			win = false;
		} // end if
	} // end if

	cout << (win ? "Fennec" : "Snuke") << endl;		
#if DEBUG
	rep (i, N){
		cerr << color[i] << ' ';
	} // end rep
	cerr << endl;
#endif

	return 0;
}

Measured memory_bytes: 14336
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		int n = sc.nextInt();
		int l = sc.nextInt();
		int min = MAX;
		int num = 0;
		for(int i = 0; i < n; i++) {
			int val = l + i;
			if(Math.abs(val) < min) {
				min = Math.abs(val);
				num = val;
			}
		}
		System.out.println(n * l + n * (n - 1) / 2 - num);
		
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

int main(){
int n,k,i;
cin>>n>>k;
vector<int> v;
for(i=0;i<n;i++)
{
    int temp;
    cin>>temp;
    v.push_back(temp);
}
int dp[n];
dp[n-1]=0;
dp[n-2]=abs(v[n-2]-v[n-1]);
for(i=n-3;i>=0;i--)
{
    int j=1;
     priority_queue<int,vector<int>,greater<int> > pq;
    while(j<=k && j+i<=n-1)
    {
        int temp=abs(v[i]-v[i+j])+dp[i+j];
        pq.push(temp);
        j++;
    }
    dp[i]=pq.top();
}
cout<<dp[0]<<endl;
}


Measured memory_bytes: 1144
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();

        long MOD = (long) 1e9 + 7;
        long ans = 1;

        int toMatch = 0;
        for (int i = 0; i < 2 * n; i++) {
            debug(ans, toMatch, s.charAt(i));
            if (toMatch == 0) {
                if (s.charAt(i) == 'B') {
                    toMatch++;
                } else {
                    System.out.println(0);
                    return;
                }
            } else {
                if (toMatch % 2 == 0) {
                    if (s.charAt(i) == 'B') {
                        toMatch++;
                    } else {
                        ans = ans * toMatch % MOD;
                        toMatch--;
                    }
                } else {
                    if (s.charAt(i) == 'B') {
                        ans = ans * toMatch % MOD;
                        toMatch--;
                    } else {
                        toMatch++;
                    }
                }
            }
        }
        if (toMatch != 0) {
            System.out.println(0);
            return;
        }
        for (int i = 1; i <= n; i++) {
            ans = (ans * i) % MOD;
        }
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 63944
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b,c,d;
	long long x,y;
	cin>>a>>b>>c>>d;
	x=a*b;
	y=c*d;
	x=max(x,y);
	cout<<x<<endl;
}

Measured memory_bytes: 256
N, L = map(int, input().split())

array = []

for i in range(1, N+1):
    azi = L+i-1
    array.append(azi)

if array[0]>0:
    print(sum(array[1:]))
elif array[-1]<0:
    print(sum(array[:-1]))
else:
    print(sum(array))




Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, A[200000];
int used[200000];

int calc_pair_number(int num) {
    int e = 2;
    while (e <= num) e *= 2;
    return e - num;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N);

    map<int, int> mii;
    int ans = 0;
    RREP(i, N) {
        if (used[i]) continue;
        int other = calc_pair_number(A[i]);
        auto lb = lower_bound(A, A + i, other) + mii[other];
        auto ub = upper_bound(A, A + i, other);
        if (lb < ub) {
            used[lb - A] = true;
            mii[other]++;
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    ll l; cin>>l;

    ll r=30;
    while((1LL << r) > l){
        r--;
    }

    vector<T> edge;
    for(ll i=0; i<r; i++){
        ll cost = (1LL << i);
        edge.eb(T(i+1, i+2, cost));
        edge.eb(T(i+1, i+2, 0));
    }

    for(ll i=r; i>=1; i--){
        ll cntpath = (1LL << (i - 1));
        if(cntpath + (1LL << r) <= l){
            edge.eb(T(i, r+1, l-cntpath));
            l -= cntpath;
        }
    }

    cout << r+1 << " " << edge.size() << endl;
    for(auto i:edge){
        cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	string s;
	while (in >> s) {
		int joi = 0, ioi = 0;
		REP(i, s.size()-3) {
			if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')joi++;
			else if (s[i] == 'I' && s[i + 1] == 'O'&&s[i + 2] == 'I')ioi++;
		}
		out << joi << endl << ioi << endl;;
	}
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  char b;
  cin >> b;
  if (b == 'A') cout << 'T' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;
  if (b == 'T') cout << 'A' << endl;
  return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
a = X
b = Y
c = 0
ans = a*A + b*B + c*C
while(a > 0 or b > 0):
  a = max(a-1, 0)
  b = max(b-1, 0)
  c += 2
  tmp = a*A + b*B + c*C
  if(tmp < ans):
    ans = tmp
  
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
vector<int> G[100000];
int cnt[100000];
int dist[100000];
void dfs(int v, int p, int d) {
	dist[v] = d;
	for (int to : G[v]) {
		if (to == p) continue;
		dfs(to, v, d + 1);
	}
}
int main() {
	int N;
	cin >> N;
	map<ll, int> idx;
	vector<ll> D;
	for (int i = 0; i < N; i++) {
		ll d;
		cin >> d;
		idx[d] = i;
		D.push_back(d);
	}
	sort(D.begin(), D.end());
	for (int i = 0; i < N; i++) cnt[i] = 1;
	vector<P> edge;
	for (int i = N - 1; i > 0; i--) {
		int v = idx[D[i]];
		ll X = D[i] + cnt[v] * 2 - N;
		if (idx.find(X) == idx.end()) {
			cout << -1 << endl;
			return 0;
		}
		int u = idx[X];
		G[u].push_back(v);
		G[v].push_back(u);
		cnt[u] += cnt[v];
		edge.emplace_back(u, v);
	}
	int v = idx[D[0]];
	dfs(v, -1, 0);
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		sum += dist[i];
	}
	if (sum != D[0]) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < N - 1; i++) {
		cout << edge[i].first + 1 << " " << edge[i].second + 1 << endl;
	}
}

Measured memory_bytes: 17780
num_array = list(map(int, input().split()))
vote_num_array = list(map(int, input().split()))
select_num = num_array[1]

val = sum(vote_num_array) * (1 / (select_num * 4))
cnt = 0

for vote_num in vote_num_array:
  if vote_num >= val:
    cnt += 1

if cnt >= select_num:
  print("Yes")
else:
  print("No")

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

int main(){
    int h, w, k; cin >> h >> w >> k;
    vector <string> s(h);
    rep(i, h) cin >> s.at(i);

    vector <vector<int>> ans(h, vector<int>(w, -1));

    int cnt = 0;
    rep(i, h){
        bool find = false;
        rep(j, w){
            //初めて見つけたとき
            if (!find && s.at(i).at(j) == '#'){
                find = true;
                cnt += 1;
                rep(k, j + 1) ans.at(i).at(k) = cnt;
                continue;
            }
            //２回目以降
            if (s.at(i).at(j) == '#'){
                cnt += 1;
                ans.at(i).at(j) = cnt;
                continue;
            }
            if (j != 0) ans.at(i).at(j) = ans.at(i).at(j - 1);
        }
        if (!find && cnt > 0){
            rep(j, w){
                ans.at(i).at(j) = ans.at(i - 1).at(j);
            }
        }
    }

    for (int i = h - 1; i >=0; i --){
        if (ans.at(i).at(0) != -1) continue;
        rep(j, w){
                ans.at(i).at(j) = ans.at(i + 1).at(j);
            }
    }


    //出力
    rep(i, h){
        rep(j, w){
            cout << ans.at(i).at(j) << " ";
        }
        cout << endl;
    }
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll sum=0;
  rep(i,s.size()) sum+=s[i]-'0';
  ll n=stoll(s);
  if(n%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	static final int MOD = 1_000_000_007;

	void run() {
		int n = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			b[i] = Math.abs(n - 1 - 2 * i);
		}
		Arrays.sort(a);
		Arrays.sort(b);
		if (!Arrays.equals(a, b)) {
			out.println(0);
			return;
		}
		int ans = 1;
		for (int i = 0; i < n / 2; i++) {
			ans *= 2;
			ans %= MOD;
		}
		out.println(ans);
	}

	static MyScanner in;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		boolean stdStreams = true;
		String fileName = Main.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
		String inputFileName = fileName + ".in";
		String outputFileName = fileName + ".out";
		
		Locale.setDefault(Locale.US);
		BufferedReader br;
		if (stdStreams) {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			br = new BufferedReader(new FileReader(inputFileName));
			out = new PrintWriter(outputFileName);
		}
		in = new MyScanner(br);
		int tests = 1;//in.nextInt();
		for (int test = 0; test < tests; test++) {
			new Main().run();
		}
		br.close();
		out.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		MyScanner(BufferedReader br) {
			this.br = br;
		}
		
		void findToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		
		String next() {
			findToken();
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


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

int main() {
  vector<int> dishes(5);
  for (int i = 0; i < 5; i++) cin >> dishes.at(i);
  
  int ignore_i = 0;
  for (int i = 0; i < 5; i++) {
    if (dishes.at(i)%10 == 0) continue;
    if (10-(dishes.at(ignore_i)%10) < 10-(dishes.at(i)%10)) ignore_i = i;
  }
  int ans = 0;
  for (int i = 0; i < 5; i++) {
    ans += dishes.at(i);
    if (dishes.at(i)%10 == 0) continue;
    if (ignore_i != i) {
      ans += 10-(dishes.at(i)%10);
    }
  }
  cout << ans << endl;
}

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

int main() {
  stack<int> S;
  int a, b, x;
  string s;

  while( cin >> s ) {
    if ( s[0] == '+' ) {
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a + b);
    } else if ( s[0] == '-' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a - b);
    } else if ( s[0] == '*' ) {
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(s.c_str()));
    }

    }
    cout << S.top() << endl;

    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 999999999999

using namespace std;

#define int long long

int n;
vector<int> a, b, c;

int32_t main(){
	int a, b, x, y;
	cin >> a >> b;
	x=a; y=b;
	int ans=INF;	

	a=-x;
	if(a<=b){
		int re=0;
		re++;
		re+=(b-a);
		ans=min(ans, re);
	}

	b=-y;
	if(a<=b){
		int re=0;
		re++; re++;
		re+=(b-a);
		ans=min(ans, re);
	}

	a=x;
	if(a<=b){
		int re=0;
		re++;
		re+=(b-a);
		ans=min(ans, re);
	}

	b=y;
	if(a<=b){
		int re=0;
		re+=(b-a);
		ans=min(ans, re);
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  string s; cin >> s;
  bool isw, isn, ise, iss;
  isw = isn = ise = iss = false;
  REP(i,s.size()){
    if(s[i] == 'W'){
      isw = true;
    }else if(s[i] == 'S'){
      iss = true;
    }else if(s[i] == 'N'){
      isn = true;
    }else if(s[i] == 'E'){
      ise = true;
    }
  }
  if(isw == ise&&isn == iss){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long n = sc.nextInt();
			long k = sc.nextInt();

			long val = 1;
			for (int i = 0; i < n; i++) {
				if (k < val) {
					val += k;
				} else {
					val *= 2;
				}
			}

			System.out.println(val);
		}
	}
}

Measured memory_bytes: 23252
num_in = [int(i) for i in input().split()]

def calc_dig_sum(num):
    num_str = str(num)
    ret = 0
    for c in num_str:
        ret += int(c)
    return ret

sum = 0
for i in range(1, num_in[0]+1):
    if num_in[1] <= calc_dig_sum(i) <= num_in[2]:
        sum += i

print(sum)

Measured memory_bytes: 73700
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		boolean fi = true;
		while(true) {
			int a = stdIn.nextInt();
			if(a == 0) break;
			if(!fi) {
				System.out.println();
			}
			else {
				fi = false;
			}
			int N10 = stdIn.nextInt();
			int N50 = stdIn.nextInt();
			int N100 = stdIn.nextInt();
			int N500 = stdIn.nextInt();
			int c = 9999;
			c += N10;
			c += N50;
			c += N100;
			c += N500;
			
			int ans10 = 0;
			int ans50 = 0;
			int ans100 = 0;
			int ans500 = 0;
			for(int i = 0; i <= N10; i++) {
				for(int j = 0; j <= N50; j++) {
					for(int k = 0; k <= N100; k++) {
						for(int la = 0; la <= N500; la++) {
							if(i * 10 + j * 50 + k * 100 + la * 500 < a) {
								continue;
							}
							else {
								int ret = (i*10 + j * 50 + k * 100 + la * 500) - a;
								int p = 0;
								p += ret/500;
								if(la > 0 && ret/500 > 0) continue;
								ret -= ret/500 * 500;
								p += ret/100;
								if(k > 0 && ret/100 > 0) continue;
								ret -= ret/100 * 100;
								p += ret/50;
								if(j > 0 && ret/50 > 0) continue;
								ret -= ret/50 * 50;
								p += ret/10;
								if(i > 0 && ret/10 > 0) continue;
								ret -= ret/10 * 10;
								
								p += N10 - i;
								p += N50 - j;
								p += N100 - k;
								p += N500 - la;
								
								
								if(p < c) {
									c = p;
									ans10 = i;
									ans50 = j;
									ans100 = k;
									ans500 = la;
								}
							}
						}
					}
				}
			}
			System.out.print((ans10 == 0)?"":"10 " +ans10+"\n");
			System.out.print((ans50 == 0)?"":"50 " +ans50+"\n");
			System.out.print((ans100 == 0)?"":"100 "+ans100+"\n");
			System.out.print((ans500 == 0)?"":"500 "+ans500+"\n");
		}
		
	}
}

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

int main(){
	int n; string s; cin>>n>>s;
	int x=0; int mx=0;
	rep(i,n){
		if(s[i]=='I') x++;
		else x--;
		mx=max(mx,x);
	}
	cout<<mx<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{

string s;
cin >> s;
string a[4] ={"Sunny", "Cloudy", "Rainy", "Sunny"}; 
for(int i = 0; i < 4; ++i){
	if(s == a[i]) {cout<<a[i+1]; break;}
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
const u32 P=1e9+7;
inline u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
inline u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
inline u32 sum(u32 a, u32 b) {return (a+=b)<P?a:a-P;}
inline u32 dif(u32 a, u32 b) {return (a-=b)&0x80000000?a+P:a;}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
	return ans;
}

const int N=5005;
const u32 Half=(P+1)/2;
int n, m;
u32 f[N], g[N];
int main() {
	n=rd();
	m=rd();
	f[m]=1;
	for(int i=1; i<=n; ++i) {
		u32 cur=0;
		for(int j=m; j>=1; --j)
			g[j]=cur=(cur*2+f[j+1])%P;
		for(int j=1; j<=m; ++j)
			f[j]=((j+1llu)*f[j]+1llu*j*g[j])%P;
	}
	u32 ans=0;
	for(int i=1; i<=m; ++i) ans=(ans+f[i])%P;
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 3800
#include <stdio.h>
#include<math.h>

int main()
{

    long n;
    scanf("%ld", &n); //読み取り
    long long sum = 0;
    long count;
    for (long i = 1; i <= n; i++)
    {
        count = n / i;
        sum += (long long)(count * (i+count*i) )/ 2;
        //printf("%lld\n", (long long)(count * (i + count * i)) / 2);

    }

    printf("%lld\n", sum);
}

Measured memory_bytes: 2152