akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

template <typename T0,typename T1,typename T2,typename F0,typename F1,typename F2,typename F3>
struct Mo{
	F0 addL;
	F1 delL;
	F2 addR;
	F3 getAns;
	
	vector<T0> v;
	T1 init_value;
	int n;
	
	Mo(vector<T0> &x,F0 f0,F1 f1,F2 f2,F3 f3,T1 iv):addL(f0),delL(f1),addR(f2),getAns(f3){
		n = x.size();
		init_value = iv;
		v = x;
	}
	
	vector<T2> get(vector<pair<int,int>> &queries){
		int sq = sqrt(n)+1;
		vector<vector<vector<int>>> q((n+sq-1)/sq,vector<vector<int>>());
		for(int i=0;i<queries.size();i++){
			q[queries[i].first/sq].push_back({queries[i].second,queries[i].first,i});
		}
		vector<T2> ret(queries.size());
		for(int i=0;i<q.size();i++){
			sort(q[i].begin(),q[i].end());
			int L = sq*i,R = sq*i;
			T1 now = init_value;
			addR(now,v[L]);
			
			for(int j=0;j<q[i].size();j++){
				int l = q[i][j][1],r = q[i][j][0];
				while(r>R){
					R++;
					addR(now,v[R]);
				}
				while(l<L){
					L--;
					addL(now,v[L]);
				}
				while(l>L){
					delL(now,v[L]);
					L++;
				}
				ret[q[i][j][2]] = getAns(now);
			}
		}
		return ret;
	}
	
};

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	vector<int> c(N);
	for(int i=0;i<N;i++){
		scanf("%d",&c[i]);
		c[i]--;
	}
	
	auto f0 = [](pair<vector<int>,int> &a,int b){
		if(a.first[b]==0)a.second++;
		a.first[b]++;
	};
	auto f1 = [](pair<vector<int>,int> &a,int b){
		a.first[b]--;
		if(a.first[b]==0)a.second--;
	};
	auto f2 = [](pair<vector<int>,int> &a,int b){
		if(a.first[b]==0)a.second++;
		a.first[b]++;
	};
	auto f3 = [](pair<vector<int>,int> &a){
		return a.second;
	};
	
	Mo<int,pair<vector<int>,int>,int,decltype(f0),decltype(f1),decltype(f2),decltype(f3)> M(c,f0,f1,f2,f3,make_pair(vector<int>(N,0),0));
	
	vector<pair<int,int>> q(Q);
	for(int i=0;i<Q;i++){
		scanf("%d %d",&q[i].first,&q[i].second);
		q[i].first--;
		q[i].second--;
	}
	
	vector<int> ans = M.get(q);
	
	for(int i=0;i<Q;i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 47420
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
dp = [0] * (N+1)
dp[0] = 1
a = set()
for _ in range(M):
    a.add(int(input()))

if 1 in a:
    if 2 in a:
        print(0)
        exit()
    dp[2] = 1
    start = 3
else:
    dp[1] = 1
    start = 2
for i in range(start, N+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= MOD

print(dp[N])


Measured memory_bytes: 12652
#include<stdio.h>

int main(){

	int N;
	scanf("%d",&N);
	int i,A[N];
	double numerator=0.0,ans;
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
		numerator += 1.0/A[i];
	}

	ans=1.0/numerator;
	printf("%f\n",ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <vector>

int main() {
	std::map<int, int> counts;

	int N;
	std::vector<int> a;

	std::cin >> N;
	a.reserve(N);

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

		if (!counts.count(a[i] - 1)) counts.insert({a[i] - 1, 0});
		if (!counts.count(a[i]))     counts.insert({a[i], 0});
		if (!counts.count(a[i] + 1)) counts.insert({a[i] + 1, 0});

		++counts[a[i] - 1];
		++counts[a[i]];
		++counts[a[i] + 1];
	}

	int max_count = 0, X = -1, max_i = 0;

	for (auto const & c : counts) {
		if (max_count < c.second) {
			max_count = c.second;
			X         = c.first;
		}
	}

	for (int i = 0; i < N; ++i) {
		max_i += abs(a[i] - X) <= 1;
	}

	std::cout << max_i << std::endl;

	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  int a[3];cin>>a[0]>>a[1]>>a[2];
  int tmp = 0;
  sort(a,a+3);
  rep(i,2){
    if(a[i] == a[i+1])tmp++;
  }
  if(tmp == 1)print("Yes");
  else print("No");
  return 0;
}



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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());  
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if( s < t ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    long long int n,m;
    cin>>n>>m;
    vector< pair<long long int,long long int> > p;
    for(int i=0;i<n;i++)
    {
        long long int a,b;
        cin>>a>>b;
        p.push_back(make_pair(a,b));
    }
    sort(p.begin(),p.end());
    long long int bott = 0;
    long long int cost =0;
    for(int i=0;i<n;i++)
    {
        if(bott<m)
        {
            cost = cost+ p[i].first*(min(p[i].second,m-bott));
            bott+=min(p[i].second,m-bott);
        }
        else
            break;
    }
    cout<<cost;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

vector<int> a;
void input(){
    fast_io();
    a.resize(3);
    cin >> a[0] >> a[1] >> a[2];
}

int solve(){
    sort(a.begin(),a.end());
    if(a[0]+a[1]==a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}   

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

Measured memory_bytes: 256
#include <stdio.h>
int p=0;
int q[2000001];
int max_index(int a,int b){
  if(q[a]>q[b])return a;
  else return b;
}
void swap(int a,int b){
  int tmp;
  tmp=q[a];
  q[a]=q[b];
  q[b]=tmp;
}

void insert(int k){
  int tmp;
  int i,j;
  p++;
  q[p]=k;
  i=p;
  while(q[i]>q[i/2] && i>1){
    swap(i,i/2);
    i=i/2;
  }
}
int extract(){
  int ret=q[1];
  int i;
  int tmp;
  int M;
  q[1]=q[p];
  p--;
  i=1;
  while(i*2 <= p ){
    if(i*2+1 <= p)
      M=max_index(i*2,i*2+1);
    else M=i*2;
    if(max_index(M,i)==M){swap(M,i);i=M;}
    else break;
    
  }
 
  return ret;
}

int main(){
  char cmd[10];
  int i,j;
  int k;
  while(1){
    scanf("%s",cmd);
    if(cmd[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    if(cmd[0]=='e'){
      if(cmd[1]=='x')
	printf("%d\n",extract());
      if(cmd[1]=='n') break;
    }
  }
  return 0;
}

Measured memory_bytes: 4692
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  cin>>n;
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  int ans = 2;
  while(ans <= n) {
    ans *= 2;
  }
  cout << ans / 2 << endl;

  return 0;
}


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(){
	int a,p;
	cin >> a >>p;
	cout << (a*3 + p)/2 << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

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

struct State {
  int which; int y; int x;
  bool operator<(const State &other) const {
    return
      (y != other.y) ? y > other.y :
      (x != other.x) ? x < other.x : which < other.which;
  };
};

const int INF = 1e9;
const int dy[] = {-2, -1, -1, 0, 0, 0, 1, 1, 2};
const int dx[] = {1, 1, 2, 1, 2, 3, 1, 2, 1};

template<typename T> struct Dijkstra {
  struct Edge { State to; T cost; };
  map<State, vector<Edge>> g;
  map<State, T> init;

  Dijkstra(int h, int w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        State s0 = {0, i, j};
        State s1 = {1, i, j};
        init[s0] = init[s1] = -1;
      }
    }
  }
  void addEdge(State u, State v, T w) {
    g[u].push_back({v, w});
  }
  map<State, T> build(vector<State> starts) {
    map<State, T> dist(init);
    using Node = pair<T, State>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    for (auto&& s : starts) {
      pq.push({dist[s] = 0, s});
    }

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
};

int main() {
  int w, h;
  while (cin >> w >> h, w) {
    vector<vector<char>> s(h, vector<char>(w));
    vector<State> starts;
    vector<State> goals;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> s[i][j];
        if (s[i][j] == 'S') {
          starts.push_back({0, i, j});
          starts.push_back({1, i, j});
        }
        if (s[i][j] == 'T') {
          goals.push_back({0, i, j});
          goals.push_back({1, i, j});
        }
      }
    }
    Dijkstra<int> g(h, w);
    for (int sy = 0; sy < h; sy++) {
      for (int sx = 0; sx < w; sx++) {
        if (s[sy][sx] == 'X') continue;
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 9; j++) {
            int ty = sy + dy[j];
            int tx = sx + ((i % 2 == 0) ? dx[j] : -dx[j]);
            if (-1 < ty && ty < h && -1 < tx && tx < w && s[ty][tx] != 'X') {
              State u = {i, sy, sx};
              State v = {i ^ 1, ty, tx};
              int w = (s[ty][tx] - '0') * (s[ty][tx] != 'S') * (s[ty][tx] != 'T');
              g.addEdge(u, v, w);
            }
          }
        }
      }
    }
    auto dist = g.build(starts);
    int ans = INF;
    for (auto&& t : goals) {
      int mn = (dist[t] != -1) ? dist[t] : INF;
      ans = min(ans, mn);
    }
    cout << ( (ans != INF) ? ans : -1 ) << endl;
  }
}



Measured memory_bytes: 4400
#include<stdio.h>
int main(void)
{
	int i, j ;
	int H, W ;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0){
			break;
		}
		
		for(i=1; i<=H; i++){
			for(j=1; j<=W; j++){
				if(i%2==1){
					if(j%2==1){
						printf("#");
					}else if(j%2==0){
						printf(".");
					}
				}else if(i%2==0){
					if(j%2==1){
						printf(".");
					}else if(j%2==0){
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main(){
	int x,y,n,m,i,j,d,count,curX,curY;
	char dir[3];
	for(;scanf("%d",&n)&&n;){
		int map[22][22];
		for(i=0;i<22;i++){
			for(j=0;j<22;j++)map[i][j]=0;
		}
		curX=10;
		curY=10;
		count=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			map[x][y]=1;
		}
		scanf("%d\n",&m);
		for(i=0;i<m;i++){
			scanf("%s %d",dir,&d);
			if(dir[0]=='N'){
				for(j=1;j<=d;j++){
					curY++;
					if(map[curX][curY]==1){
						map[curX][curY]=0;
						count++;
					}
				}
			}
			else if(dir[0]=='S'){
				for(j=1;j<=d;j++){
					curY--;
					if(map[curX][curY]==1){
						map[curX][curY]=0;
						count++;
					}
				}
			}
			else if(dir[0]=='W'){
				for(j=1;j<=d;j++){
					curX--;
					if(map[curX][curY]==1){
						map[curX][curY]=0;
						count++;
					}
				}
			}
			else if(dir[0]=='E'){
				for(j=1;j<=d;j++){
					curX++;
					if(map[curX][curY]==1){
						map[curX][curY]=0;
						count++;
					}
				}
			}
		}
		printf("%s\n",count==n?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	int k, s, i, j ,count=0;

	scanf("%d%d", &k, &s);

	for (i = 0; i <= s && i <= k; i++) {
		for (j = 0; j <= s && j <= k; j++) {
			if (s - i - j <= k&&s-i-j>=0){
				count++;
			}
		}
	}

	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
 
#define MAX 101
 
int max(int a,int b)
{
    int M;
    M=a;
    if(M < b) M=b;
    return M;
}
 
int main(void)
{
    int i,j,N,W,v[MAX],w[MAX],dp[MAX][10001];
     
    scanf("%d%d",&N,&W);
    v[0]=0;
    w[0]=0;
    for(i=1;i<=N;i++)
    {
        scanf("%d%d",&v[i],&w[i]);
    }
    for(i=0;i<=W;i++)
    {
        dp[0][i]=0;
    }
    for(i=1;i<=N;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(w[i]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    printf("%d\n",dp[N][W]);
    return 0;
}


Measured memory_bytes: 5736
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < 3; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            v[x-1] |= (1 << i);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto &&j : {4, 6, 7}) if(v[i] == j) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <bitset>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int n = s.size();

  long long sum = 0;
  for(int bit = 0; bit < (1 << n - 1);  bit++){
    long long t = s[0] - '0';
    for(int i = 0; i < n - 1; i++){
      if(bit & 1 << i){
        sum += t;
        t = s[i + 1] - '0';
      }else{
        t *= 10;
        t += s[i + 1] - '0';
      }
    }
    sum += t;
  }
  cout << sum << endl;
}

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

int main() {
    long N,M;
    cin>>N>>M;
    vector<set<long>> edge(N,set<long>());
    for(int i=0;i<M;i++){
        long a,b;
        cin>>a>>b;
        
        edge.at(a-1).insert(b-1);
        edge.at(b-1).insert(a-1);
    }
    
    for(auto ite0=edge.at(0).begin();ite0!=edge.at(0).end();++ite0){
        if(edge.at(*ite0).count(N-1)){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 28416
#include <cstdio>

bool b_search(int s[], int n, int t) {
    int beg = 0, end = n;
    while (beg < end) {
        int mid = (end + beg) / 2;
        if (s[mid] == t) return true;
        else if (s[mid] > t) end = mid;
        else beg = mid + 1;
    }
    return false;
}

int
main(int argc, const char *argv[])
{
    int n;
    int S[100000];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &S[i]);

    int q;
    scanf("%d", &q);
    int count = 0;
    for (int i = 0; i < q; ++i) {
        int t;
        scanf("%d", &t);
        if (b_search(S, n, t)) ++count;
    }
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 3064
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    if((a + b) % 2 == 0) {
        std::cout << (a + b) / 2 << std::endl;
    } else {
        std::cout << ((a + b) / 2) + 1 << std::endl;
    }
}

Measured memory_bytes: 256
(gets.to_i).times{
  n, k = gets.split(" ").map{|str| str.to_i}
  a = gets.split(" ").map{|str| str.to_i}
  if n>1 && n>k
    l = a[-1]-a[0]
    d = Array.new(n-1){|i| a[i+1]-a[i]}.sort
    (k-1).times{l -= d[-1] ; d = d[0..-2]}
    puts l
  else
    puts 0
  end
}

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B&&A!=C){
    cout<<"Yes"<<endl;
  }
  else if(A==C&&A!=B){
    cout<<"Yes"<<endl;
  }
  else if(C==B&&A!=C){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
S = input()
ans = [0 for i in range(len(S))]

odd = 0
even = 0
for i in range(len(S)):
    if S[i] == 'R':
        tmp = even
        even = odd + 1
        odd = tmp
    else:
        ans[i-1] += even
        ans[i] += odd
        odd = 0
        even = 0

for i in range(len(S)):
    if S[-i-1] == 'L':
        tmp = even
        even = odd + 1
        odd = tmp
    else:
        ans[-i] += even
        ans[-i-1] += odd
        odd = 0
        even = 0

print(*ans)


Measured memory_bytes: 47760
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

void push(int);
int pop(void);

int s[100];
int k=0;

int main(){
	char str[100];
	int a,b;
	while(scanf("%s",str) != EOF){
		switch(str[0]){
			case '+':
				push(pop()+pop());
				break;
			case '-':
				b=pop();
				a=pop();
				push(a-b);
				break;
			case '*':
				push(pop()*pop());
				break;
			default:
				push(atoi(str));
				break;
		}
	}
	cout << pop() << endl;
	return 0;
}

void push(int a){
	s[k++]=a;
}

int pop(void){
	return s[--k];
}

Measured memory_bytes: 1164
<?php

function prime_factors(int $n) : array {
    $i = 2;
    $factors = [];
    while ($i * $i <= $n) {
        if ($n % $i) $i += 1;
        else {
            $n /= $i;
            $factors[] = $i;
        }
    }
    if ($n > 1) $factors[] = $n;
    return $factors;
}
fscanf(STDIN, "%d", $input);
$ceil = (int)ceil(pow($input,0.5));

if($ceil > 100) {
    $sa = (int)($ceil * (int)($ceil - 10));
    $sa2 = $sa - $input;
    $sa3 = $sa2 + ($ceil * 10);
}else{
    $sa3 = (int)($ceil * $ceil - $input);
}
if($sa3 == 0){
    $ans1 = 0;
    $ans2 = 0;
}else{
    $list = prime_factors($sa3);
    $count = count($list);
    $ans1 = 1;
    $ans2 = 1;
    if($count > 1){
        for($i = 0; $i<$count; $i++){
            if($i < intdiv($count, 2)){
                $ans1 = $ans1 * $list[$i];
            }else{
                $ans2 = $ans2 * $list[$i];
            }


        }
    }else{
        if(isset($list[0])) {
            $ans1 = $list[0];
        }else{
            $ans1 = 1;
        }
    }
}
echo "0 0 ".$ceil. " ". $ans1. " ".$ans2. " ". $ceil;

Measured memory_bytes: 4728
#define _CRT_SECURE_NO_WARNING

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	a=a-2*b;
	if(a<0) a=0;
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int ans = 0;
    for (int i = 1; i < s.length; i++) {
        if (s[i-1] != s[i]) ans++;
    }
    return ans;
}

void main() {
    auto s = read!string;
    writeln(calc(s));
}


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

int K,S;

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

    int ans=0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            if(0<=S-i-j && S-i-j<=K) ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = [1]*N
for _ in range(M):
  A, B = map(lambda x:int(x)-1, input().split())
  if H[A] < H[B]:
    ans[A] = 0
  elif H[A] == H[B]:
    ans[A] = 0
    ans[B] = 0
  else:
    ans[B] = 0
print(sum(ans))

Measured memory_bytes: 84940
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int cnt=1;
    int x;
    while (cin>>x,x) printf("Case %d: %d\n",cnt,x),++cnt;
    return 0;
}


Measured memory_bytes: 3140
#include<cstdio>
void swap(int &x,int &y)
{
	int t=x;
	x=y;
	y=t;
	return ;
}
int main()
{
	int a,b,c;
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		int t;
		swap(a,b);
		swap(a,c);
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
} 

Measured memory_bytes: 1708
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, int> p;

#define MOD 1000000007
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> c(N + 1LL, 2LL);

    for(ll i = 2LL; i * i <= N; i++) {
        for(ll j = 2LL; i * j <= N; j++) {
            if(i == j) c[i * j]++;
            else {
                if(j <= sqrt(N)) c[i * j]++;
                else c[i * j] += 2LL;
            }
        }
    }

    ll ans = 1LL;

    for(ll i = 2LL; i <= N; i++) {
        ans += i * c[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 81264
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m;
vi G[MAXN];
int A[MAXN];

int vis[MAXN];
void dfs( int u ) {
	if( vis[u] ) return;
	vis[u] = 1;
	for( int x : G[u] ) dfs( x );
}

void solve() {
	cin >> n >> m;
	rep( i , 1 , m ) {
		static int u , v;
		scanf("%d%d",&u,&v);
		G[u].pb( v ) , G[v].pb( u );
	}
	int cnt = 0;
	rep( i , 1 , n ) if( !vis[i] ) dfs( i ) , ++ cnt;
	cout << cnt - 1 << endl;
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


Measured memory_bytes: 12316
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 105

struct Edge{
	Edge(int arg_to,ll arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	ll cost;
};

int N;
ll W;
vector<Edge> G[SIZE];
ll value[SIZE];

void init(vector<ll> &V){

	V[0] = 0;
	for(ll i = 1; i <= W; i++){

		V[i] = -HUGE_NUM;
	}
}

vector<ll> dfs_USE(vector<ll> dp,int node_id,int parent){

	vector<ll> ret = dp;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent)continue;

		vector<ll> work_USE = dfs_USE(ret,child,node_id);

		for(int k = W; k-G[node_id][i].cost >= 0; k--){

			if(work_USE[k-G[node_id][i].cost] == -HUGE_NUM)continue;

			ret[k] = max(ret[k],work_USE[k-G[node_id][i].cost]);
		}
	}

	for(int i = 0; i <= W; i++){
		if(ret[i] == -HUGE_NUM)continue;
		ret[i] += value[node_id];
	}

	return ret;
}

vector<ll> dfs_NOT(int node_id,int parent){

	vector<ll> ret(W+1);
	init(ret);

	vector<ll> first_dp(W+1);
	init(first_dp);

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent)continue;

		vector<ll> work_NOT = dfs_NOT(child,node_id);
		for(int k = 0; k <= W; k++){

			ret[k] = max(ret[k],work_NOT[k]);
		}

		vector<ll> work_USE = dfs_USE(first_dp,child,node_id);

		for(int k = 0; k <= W; k++){

			ret[k] = max(ret[k],work_USE[k]);
		}
	}
	return ret;
}


int main(){

	scanf("%d %lld",&N,&W);

	for(int i = 0; i < N; i++){

		scanf("%lld",&value[i]);
	}

	int from,to;
	ll cost;

	for(int i = 0; i < N-1; i++){

		scanf("%d %d %lld",&from,&to,&cost);
		from--;
		to--;

		G[from].push_back(Edge(to,cost));
		G[to].push_back(Edge(from,cost));
	}

	vector<ll> ret_NOT = dfs_NOT(0,-1);

	vector<ll> first_dp(W+1);

	init(first_dp);

	vector<ll> ret_USE = dfs_USE(first_dp,0,-1);

	ll ans = 0;

	for(int i = 0; i <= W; i++){

		ans = max(ans,max(ret_NOT[i],ret_USE[i]));
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 121592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strND = br.readLine().split(" ");
        int N = Integer.parseInt(strND[0]);
        int D = Integer.parseInt(strND[1]);
        
        int[][] X = new int[N][D];
        
        for(int i = 0; i < N; i++){
            String[] strXi = br.readLine().split(" ");
            X[i] = Stream.of(strXi).mapToInt(Integer::parseInt).toArray();
        }
        
        int ans = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j < N; j++){
                
                int total = 0;
                for(int k = 0; k < D; k++){
                    total += Math.pow(Math.abs(X[i][k] - X[j][k]), 2);
                }
                
                double x = Math.sqrt(total);
                if ( x == (int) x ) ans++;
                
            }
        }
        
        System.out.println(ans);
        
        br.close();
    }
}


Measured memory_bytes: 26580
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  for(ll & e:c)cin>>e;
  for(int i=0;i<n;i++){
    if(i%2==0){
      a[i/2]=c[i];
    }
    else{
      b[i/2+1]=c[i];
    }
  }
  if(n%2==0){
    for(int i=1;i<=n/2;i++){
      cout<<b[n/2-i+1]<< ' ';
    }
    for(int i=0;i<n/2;i++){
      cout<<a[i] << ' ';
    }  
  }
  else{
    for(int i=0;i<=n/2;i++){
      cout<<a[n/2-i]<<' ';
    }
    for(int i=1;i<=n/2;i++){
      cout << b[i]<< ' ';
    }  
  }
cout << endl;
      return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<pii,int>> q(n);
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        q[i].first.first = s;
        q[i].first.second = -p;
      	q[i].second = i + 1;
    }
    sort(q.begin(),q.end());
    rep(i,n) cout << q[i].second << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long; using ld = long double;
using P = pair<int, int>;

int main() {
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;

    int max = 0, maxi = 0;

    rep(i,3) {
      if (max < a[i]) {
        max = a[i];
        maxi = i;
      }
    }

    a[maxi] = a[maxi] * pow(2,k);
    
    int ans = 0;
    rep(i,3) {
      ans += a[i];
    }
    cout << ans << endl;
    return 0;
}



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

const int LEN = 100;
const int INF = 10000;
int tttime[LEN][LEN];
int cost[LEN][LEN];


int main(void){
	while(1){
		//init
		int rosen,eki,a,b,incost,intttime;
		for(int i=0; i<LEN; i++){ 
			for(int j=0; j<LEN; j++)
				tttime[i][j] = cost[i][j] = INF;
		}
		for(int i=0; i<LEN; i++)
			tttime[i][i] = cost[i][i] = 0;
	
		//in
		cin >> rosen >> eki; 
		if(rosen==0&&eki==0)break;
		for(int i=0; i<rosen; i++){
			cin >> a >> b >> incost >> intttime;
			a--; b--;
			cost[a][b] = cost[b][a] = incost;
			tttime[a][b] = tttime[b][a] = intttime;
		}

		//calc
		for(int k=0; k<eki; k++){
			for(int i=0; i<eki; i++){
				for(int j=0; j<eki; j++){
					tttime[i][j] = min(tttime[i][j],tttime[i][k]+tttime[k][j]);
					cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
				}
			}
		}

		//out
		int toi;
		cin >> toi;
		for(int i=0; i<toi; i++){
			int a,b,r;
			cin >> a >> b >> r;
			a--; b--;
			if(r==0)
				cout << cost[a][b] << endl;
			else
				cout << tttime[a][b] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1236
//be name khoda
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int maxn = 310;
const int mod = 1e9+7;
const ll INF = 1e18;

int n;
ld dp[maxn][maxn][maxn];

int main()
{
    cin>> n;
    int n1 = 0, n2 = 0, n3 = 0;
    for(int i = 0; i < n; i++){
        int x; cin>> x;
        if(x == 1) n1++;
        if(x == 2) n2++;
        if(x == 3) n3++;
    }

    for(int k = 0; k <= n; k++)
        for(int j = 0; j <= n; j++)
            for(int i = 0; (i+j+k) <= n; i++)
            {
                if(!i && !j && !k) continue;

                if(i)
                    dp[i][j][k] += ((double)i/n) * (dp[i-1][j][k] + 1);
                if(j)
                    dp[i][j][k] += ((double)j/n) * (dp[i+1][j-1][k] + 1);
                if(k)
                    dp[i][j][k] += ((double)k/n) * (dp[i][j+1][k-1] + 1);
                dp[i][j][k] += ((double)(n-(i+j+k))) / n;
                dp[i][j][k] *= n;
                dp[i][j][k] /= (double)(i+j+k);
            }
    cout<< fixed << setprecision(12) << dp[n1][n2][n3];
}










Measured memory_bytes: 450688
#include <iostream>

using namespace std;

int q1, b, c1, c2, q2;

int check (int x )
{
	int y = (b - c1*x)/c2;

	if (x + y < q1 ) return -1;
	if (y < 0 ) return -1;
	if (b - c1*x < 0 ) return -1;
	
	return y;
}

int main()
{
	while (cin >> q1 >> b >> c1 >> c2 >> q2 && q1 ){

		int x, y;
		for (x = q2; x > 0; x-- ){
			if ( (y = check (x ) ) != -1 ){
				cout << x << ' ' << y << endl;
				break;
			} // end if
		} // end for

		if (x == 0 ){
			cout << "NA" << endl;
		} // end if

	} // end while

	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { d, r, u, l , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D array to 1D array. (Zero-indexed)
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) {
	int r = n / nCol, c = n % nCol;
	return ii(r, c);
}

void inter(string s) {
	cout << s << endl;
	fflush(stdout);
}

const int NN = 2e6 + 10;
ll fact[NN];

void init() {
	fact[0] = 1;
	for (int i = 1; i < NN; ++i) fact[i] = (fact[i - 1] * 1LL * i) % MOD;
}

ll nCr(ll n, ll r) {
	auto modInverse = [](ll a) { 
		auto power = [](ll base, ll exp) {
			ll ans = 1;
			base %= MOD;
			while (exp > 0) {
				if (exp & 1) ans = (ans * base) % MOD;
				exp >>= 1;
				base = (base * base) % MOD;
			}
			return ans;
		};
		return power(a, MOD - 2); 
	};
	return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r])) % MOD;
}



int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << endl;



	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n - 1; i++){
        sum += (n-1) / i;
    }
    cout << sum << endl;
    return 0;
}
 
 //vector<int> a(3);
 //a.at(0);
 //a.size();
 //vector<vector<int>> a(3, vector<int>(3));
 //uint64_t sum = 0;
 //max(a, b);
 //min(a, b);
 //swap(a, b);
 //sort(vec.begin(), vec.end());  昇順
 //reverse(vec.begin(), vec.end());  降順


Measured memory_bytes: 3632
#include <cstdio>
#include <utility>
#include <queue>
using namespace std;
int i,n,L,t,tr[100002],s;
int main(){
	typedef pair<int,int>pii;
	priority_queue<pii> qu;
	pii p;
	
	for(scanf("%d%d",&n,&L);i++<n;)scanf("%d",tr+i);

	for(;--i;)
		tr[i]>tr[i-1]&tr[i]>tr[i+1]?
			qu.push(pii(tr[i]-L,i)),
			tr[i]=L:0;

	for(;!qu.empty();		n&&n!=L&n>tr[s+2]?
			qu.push(pii(t-L+n,s+1)),
			tr[s+1]=L
		:0)
		p=qu.top(),
		qu.pop(),
		
		t=p.first,
		tr[s=p.second]=0,
		
		n=tr[s-1],
		n&&n!=L&n>tr[s-2]?
			qu.push(pii(t-L+n,s-1)),
			tr[s-1]=L
		:0,
		n=tr[s+1];

	
	printf("%d\n",-t);
}

Measured memory_bytes: 1584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int  n,m;
  cin>>n>>m;
  int l,r;
  int ma=0;
  int mi=100000;
  for(int i=1;i<=m;i++){
    cin>>l>>r;
    ma=max(ma,l);
    mi=min(mi,r);


  }
  int cnt =0;
  for(int i=1;i<=n;i++){
    if(i>=ma&&i<=mi){

        cnt++;
    }
  }

cout<<cnt<<endl;
}






Measured memory_bytes: 256
N = int(input())

A_list = [0] * N
B_list = [0] * N
C_list = [0] * N

for i in range(N):
    a, b, c = map(int, input().split())
    A_list[i] = a
    B_list[i] = b
    C_list[i] = c

dp = [[0, 0, 0] for j in range(N)]

for i in range(N):
    if i == 0:
        dp[0][0] = A_list[0]
        dp[0][1] = B_list[0]
        dp[0][2] = C_list[0]
    else:
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A_list[i]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B_list[i]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C_list[i]

print(max(dp[N - 1]))


Measured memory_bytes: 34676
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        if (k > a) {
            b = Math.max(0, b - (k - a));
            a = 0;
        } else {
            a -= k;
        }
        System.out.println(a + " " + b);
    }
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

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

int n;

ll a[MAX_N], b[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(b[i]));
  }

  ll bank_a = 0LL;
  ll bank_b = 0LL;

  for (int i = 0; i < n; ++i) {
    ll diff = a[i] - b[i];

    if (diff == 0LL) continue;

    if (diff < 0LL) {
      ll need_a = abs(diff / 2LL);
      ll use_a = min(bank_a, need_a);

      bank_a -= use_a;
      bank_b += need_a - use_a;
    } else {
      ll need_b = diff;
      ll use_b = min(bank_b, need_b);

      bank_b -= use_b;
      bank_a += need_b - use_b;
    }
  }

  string ans = (bank_a * 2 <= bank_b) ? "Yes" : "No";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
char in[110];
int main(){
	int a;scanf("%d%s",&a,in);
	if(strlen(in)<=a)printf("%s\n",in);
	else{
		for(int i=0;i<a;i++)printf("%c",in[i]);
			printf("...\n");
	}
}

Measured memory_bytes: 1624
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(s: &str) -> &'static str {
    let up: u32 = s[0..2].parse().unwrap();
    let low: u32 = s[2..4].parse().unwrap();

    if (1 <= up && up <= 12) {
        if (low == 0 || (13 <= low && low <= 99)) {
            "MMYY"
        } else {
            "AMBIGUOUS"
        }
    } else {
        if (1 <= low && low <= 12) {
            "YYMM"
        } else {
            "NA"
        }
    }
}

fn main() {
    let line = read_line!();
    println!("{}", solve(&line));
}

#[test]
fn solve_test() {
    assert_eq!(solve("1905"), "YYMM");
    assert_eq!(solve("0112"), "AMBIGUOUS");
    assert_eq!(solve("1700"), "NA");
}


Measured memory_bytes: 4352
from collections import Counter

s=input()
c=Counter(s)
if ((c['N']==0 and c['S']==0) or (c['N']!=0 and c['S']!=0)) and ((c['W']==0 and c['E']==0) or (c['W']!=0 and c['E']!=0)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
line = input()

a = [int(n) for n in line.split()]

k = int(input())

a.sort()
largest = a[-1]*2

for i in range(k-1):
    largest = largest * 2

a[-1] = largest
print(sum(a))

#k = int(input())


#z = a+b+x
#
#if x < a:
#    print("NO")
#elif x > a+b:
#    print("NO")
#elif x <= a+b:
#    print("YES")
#


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

ll N, M;
vll A;

ll cost[] = {INF, 2,5,5,4,5,6,3,7,6};
ll val[10];

deque<ll> out;
ll mincost;
ll maxdig;

bool flagout = false;

void dfs(ll depth){
    if (flagout == true) return;

    
    if (N == 0){
        ll si = (ll)out.size();
        for(auto i = 0; i<si; i++){
            cout << out.front();
            out.pop_front();
        }
        cout << endl;
        flagout = true;
    }

    for(auto j= 9; j>0; j--){
            
        if (val[j] == 0) continue;
        if (N - cost[j] >= (maxdig-depth-1)*mincost){ // iを使って達成可能な桁が変わるか
            if (N < cost[j]) continue;
            N -=cost[j];
            out.push_back(j);
            dfs(depth+1);
            if (flagout == true) return;
            N += cost[j];
            out.pop_back();
            continue;
        }
    }
    
}

int main() {

    cin >> N >> M;
    A.resize(M);
    cin >>A;
    
    maxdig = 0;
    
    for(auto i = 0; i<M; i++){
        if (maxdig < N/cost[A[i]]) maxdig = N/cost[A[i]];
        val[A[i]] = 1;
        
    }

    if (val[3] == 1) val[2] = 0;
    if (val[5] == 1) {
        val[3] = 0;
        val[2] = 0;
    }
    if(val[9] == 1){
        val[6] = 0;
    }
    
    mincost = 100;
    
    for(auto i = 0; i<M; i++){
        if (mincost > cost[A[i]]) mincost = cost[A[i]];
    }


    while(!flagout){
        
        dfs(0);
        maxdig--;
    }
    
    
    
    return 0;
}













Measured memory_bytes: 512