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

#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

#define MAXX 10005

#define PI   3.14159265358979323846264338327950

#define F first
#define S second

#define ll 	 long long int

#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll x = n-1;
	ll h = 0;
	for(ll i = 0; i < n - 1 ; i++){
		if(s[i]== 'W'){
			for(ll j = x; j >= 0; j --){
			if(s[j] == 'R' || !j){
				x = j;
				break;
			}
		}
		if(s[i] == 'W' && s[x] == 'R' && x > i){
			swap(s[x], s[i]);
			h ++;
			x --;
		}
		}

	}
	cout << h << endl;
	return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define FOR(i, j, n) for(int i=j;i<n;i++)
#define FORE(i, j, n) for(int i=j;i<=n;i++)

int N;
int data[101][101];
long long buf[101][101];

using namespace std;

long search() {
    buf[1][1] = data[1][1];
    long long max = data[1][1];

    FOR(i, 2, N) {
        buf[1][i] = buf[1][i - 1] + data[1][i];
        buf[i][1] = buf[i - 1][1] + data[i][1];
    }

    FOR(i, 2, N) FOR(j, 2, N) buf[i][j] = data[i][j] + buf[i - 1][j] + buf[i][j - 1] - buf[i - 1][j - 1];

    FOR(i, 1, N) {
        FOR(j, 1, N) {
            FOR(k, i, N) {
                FOR(l, j, N) {
                    long long t = buf[k][l] + buf[i - 1][j - 1] - buf[i - 1][l] - buf[k][j - 1];
                    if (max < t) max = t;
                }
            }
        }
    }

    return max;
}

int main() {
    std::cin >> N;
    N += 1;
    memset(data, 0, sizeof(data));
    memset(buf, 0, sizeof(buf));
    FOR(i, 1, N) FOR(j, 1, N) std::cin >> data[i][j];
    std::cout << search() << std::endl;

    return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <queue>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
const int N=200010,INF=0x7f7f7f7f;
int a[N];
inline int pamin(int x,int y){
	return x==-1?y:y==-1?x:a[x]<a[y]?x:y;
}
namespace seg{
	struct Node;
	typedef Node* node;
	struct Node{
		int l,m,r;
		node lson,rson;
		int val[2];
		inline void up(){
			val[0]=pamin(lson->val[0],rson->val[0]);
			val[1]=pamin(lson->val[1],rson->val[1]);
		}
	}*rt;
	node build(int l,int r){
		static node n=new Node[N<<1];
		node x=n++;
		x->l=l,x->m=(l+r)>>1,x->r=r;
		if(l==r){
			x->val[l&1]=l;
			x->val[!(l&1)]=-1;
		}else{
			x->lson=build(l,x->m);
			x->rson=build(x->m+1,r);
			x->up();
		}
		return x;
	}
	int ask(node x,int l,int r,bool d){
		if(x->l==l&&x->r==r){
			return x->val[d];
		}
		if(r<=x->m){
			return ask(x->lson,l,r,d);
		}
		if(l>x->m){
			return ask(x->rson,l,r,d);
		}
		return pamin(ask(x->lson,l,x->m,d),ask(x->rson,x->m+1,r,d));
	}
}
int iteml[N],itemr[N],items=0;
namespace G{
	const int E=N+(N>>1);
	int to[E],bro[E],head[N],e=0;
	inline void init(){
		memset(head,-1,sizeof(head));
	}
	inline void ae(int u,int v){
		if(~v){
			to[e]=v,bro[e]=head[u],head[u]=e++;
		}
	}
	struct icmp{
		inline bool operator () (const int &x,const int &y){
			return a[iteml[x]]!=a[iteml[y]]?a[iteml[x]]>a[iteml[y]]:a[itemr[x]]>a[itemr[y]];
		}
	};
	void bfs(int s){//+output
		priority_queue<int,vector<int>,icmp>q;
		q.push(s);
		while(!q.empty()){
			int x=q.top();
			q.pop();
			printf("%d %d ",a[iteml[x]],a[itemr[x]]);
			for(int i=head[x];~i;i=bro[i]){
				q.push(to[i]);
			}
		}
	}
}
int solve(int l,int r){
	if(l>r){
		return -1;
	}
	assert((l&1)!=(r&1));
	int x=++items;
	iteml[x]=seg::ask(seg::rt,l,r,l&1);
	itemr[x]=seg::ask(seg::rt,iteml[x]+1,r,!(l&1));
	G::ae(x,solve(l,iteml[x]-1));
	G::ae(x,solve(iteml[x]+1,itemr[x]-1));
	G::ae(x,solve(itemr[x]+1,r));
	return x;
}
int main(){
	int n=ni;
	for(int i=1;i<=n;i++){
		a[i]=ni;
	}
	seg::rt=seg::build(1,n);
	G::init();
	int s=solve(1,n);
	assert(items==(n>>1));
	G::bfs(s);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 29184
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N , K ,x;
  cin >> N >> K;
  x = N;
  while(true){
    if(x > K){
      x %= K;
    }else if(K - x < x){
      x = K - x;
    }else {
      break;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
import heapq

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

left = [0] * (N + 1)
right = [0] * (N + 1)
lq = a[:N]
rq = [0] * N
for i in range(N):
    rq[i] = -a[2 * N + i]
heapq.heapify(lq)
heapq.heapify(rq)
left[0] = sum(lq)
right[-1] = -sum(rq)
for i in range(N):
    new = a[N + i]
    heapq.heappush(lq, new)
    old = heapq.heappop(lq)
    left[i + 1] = left[i] - old + new
for i in range(N):
    new = -a[2 * N - i - 1]
    heapq.heappush(rq, new)
    old = heapq.heappop(rq)
    right[N - i - 1] = right[N - i] + old - new
ans = - 10 ** 20
for i in range(N + 1):
    ans = max(left[i] - right[i], ans)
print(ans)


Measured memory_bytes: 119976
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; string s; cin >> n >> s;
  REP(x, 2) REP(y, 2) {
    vector<int> ans{x, y};
    FOR(i, 1, n - 1) {
      if (ans[i] == 0) {
        ans.emplace_back(s[i] == 'o' ? ans[i - 1] ^ 1 : ans[i - 1]);
      } else {
        ans.emplace_back(s[i] == 'o' ? ans[i - 1] : ans[i - 1] ^ 1);
      }
    }
    bool ok = true;
    if (ans[0] == 0) {
      ok &= (s[0] == 'o' ? ans[1] != ans[n - 1] : ans[1] == ans[n - 1]);
    } else {
      ok &= (s[0] == 'o' ? ans[1] == ans[n - 1] : ans[1] != ans[n - 1]);
    }
    if (ans[n - 1] == 0) {
      ok &= (s[n - 1] == 'o' ? ans[n - 2] != ans[0] : ans[n - 2] == ans[0]);
    } else {
      ok &= (s[n - 1] == 'o' ? ans[n - 2] == ans[0] : ans[n - 2] != ans[0]);
    }
    if (ok) {
      REP(i, n) cout << (ans[i] == 0 ? 'W' : 'S');
      cout << '\n';
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}


Measured memory_bytes: 1360
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#define rec(n,i) for(int i=0;i<n;i++)
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a + b + c;
	if (max(a, max(b, c)) == sum - max(a, max(b, c)))cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <locale>
using namespace std;


int main() {
    string s1,s2;
   int t=0;
    cin>>s1>>s2;
    if(s1.length()>s2.length())
        {
        cout<<"GREATER";
        t=1;
    }
    else if(s2.length()>s1.length())
        {
        cout<<"LESS";
        t=1;
    }
    else if(s2.compare(s1)==0)
        {
         cout<<"EQUAL";
         t=1;
    }
    else
        {
        for(int i=0;i<s2.length();i++)
            {
            if(s1[i]>s2[i])
                {
                cout<<"GREATER";
                t=1;
                break;
            }
            else if(s2[i]>s1[i])
                {
                 cout<<"LESS";
                t=1;
                break;
            }
        }
    }
    if(t==0)
        cout<<"EQUAL";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var t=sc.S;
		int n=t.Length;
		bool b=true;StringBuilder sb=new StringBuilder();
		int g=1;
		for(int i = 0;i<n-1;i++) {
			if(i<n/2){
				if(t[i]!=t[n-i-2]){
					b=false;
					break;
				}
			}
			sb.Append(g).Append(" ").Append(i+2).Append("\n");
			if(i<n/2&&t[i]=='1'){g=i+2;}

		}
		if(t[n-1]=='1'||t[0]=='0'){b=false;}
		if(!b){Console.WriteLine("{0}",-1);}
		else{Console.Write(sb);}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 21212
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<char> u(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> u[i];

  map<int, vector<int>> mu, mr, md, ml, mu_s, mu_d, mr_s, mr_d, md_s, md_d, ml_s, ml_d;
  for (int i = 0; i < n; i++) {
    switch (u[i]) {
      case 'U': {
        mu[x[i]].push_back(y[i]);
        mu_s[x[i] + y[i]].push_back(x[i]);
        mu_d[x[i] - y[i]].push_back(x[i]);
        break;
      }
      case 'R': {
        mr[y[i]].push_back(x[i]);
        mr_s[x[i] + y[i]].push_back(x[i]);
        mr_d[x[i] - y[i]].push_back(x[i]);
        break;
      }
      case 'D': {
        md[x[i]].push_back(y[i]);
        md_s[x[i] + y[i]].push_back(x[i]);
        md_d[x[i] - y[i]].push_back(x[i]);
        break;
      }
      case 'L': {
        ml[y[i]].push_back(x[i]);
        ml_s[x[i] + y[i]].push_back(x[i]);
        ml_d[x[i] - y[i]].push_back(x[i]);
        break;
      }
    }
  }

  int r = INF;

  // ^ and v
  for (auto& [x, vu] : mu) {
    if (!md.count(x)) continue;
    auto& vd = md[x];
    sort(vu.begin(), vu.end());
    sort(vd.begin(), vd.end());
    for (auto y : vu) {
      auto it = lower_bound(vd.begin(), vd.end(), y);
      if (it == vd.end()) continue;
      r = min(r, 5 * (*it - y));
    }
  }

  // > and <
  for (auto& [y, vr] : mr) {
    if (!ml.count(y)) continue;
    auto& vl = ml[y];
    sort(vr.begin(), vr.end());
    sort(vl.begin(), vl.end());
    for (auto x : vr) {
      auto it = lower_bound(vl.begin(), vl.end(), x);
      if (it == vl.end()) continue;
      r = min(r, 5 * (*it - x));
    }
  }

  // > and ^
  for (auto& [s, vr] : mr_s) {
    if (!mu_s.count(s)) continue;
    auto& vu = mu_s[s];
    sort(vr.begin(), vr.end());
    sort(vu.begin(), vu.end());
    for (auto x : vr) {
      auto it = lower_bound(vu.begin(), vu.end(), x);
      if (it == vu.end()) continue;
      r = min(r, 10 * (*it - x));
    }
  }

  // > and v
  for (auto& [d, vr] : mr_d) {
    if (!md_d.count(d)) continue;
    auto& vd = md_d[d];
    sort(vr.begin(), vr.end());
    sort(vd.begin(), vd.end());
    for (auto x : vr) {
      auto it = lower_bound(vd.begin(), vd.end(), x);
      if (it == vd.end()) continue;
      r = min(r, 10 * (*it - x));
    }
  }

  // ^ and <
  for (auto& [d, vu] : mu_d) {
    if (!ml_d.count(d)) continue;
    auto& vl = ml_d[d];
    sort(vu.begin(), vu.end());
    sort(vl.begin(), vl.end());
    for (auto x : vu) {
      auto it = lower_bound(vl.begin(), vl.end(), x);
      if (it == vl.end()) continue;
      r = min(r, 10 * (*it - x));
    }
  }

  // v and <
  for (auto& [s, vd] : md_s) {
    if (!ml_s.count(s)) continue;
    auto& vl = ml_s[s];
    sort(vd.begin(), vd.end());
    sort(vl.begin(), vl.end());
    for (auto x : vd) {
      auto it = lower_bound(vl.begin(), vl.end(), x);
      if (it == vl.end()) continue;
      r = min(r, 10 * (*it - x));
    }
  }

  if (r == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << r << endl;
  }
}


Measured memory_bytes: 70464
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int max = 0;
  int sum = 0;
  for(int i = 0;i < n;i++){
    int p = sc.nextInt();
    sum += p;
    max = Math.max(max,p);
  }
  System.out.println((int)(sum - (max/2)));
}}


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

using namespace std;

int main() {
  int n, K;
  scanf("%d %d", &n, &K);
  vector< vector<int> > g(n);
  vector<int> vv(n), uu(n);
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d %d", &v, &u);
    v--; u--;
    g[v].push_back(u);
    g[u].push_back(v);
    vv[i] = v;
    uu[i] = u;
  }
  vector<int> depth(n);

  function<void(int,int)> dfs = [&](int v, int p) {
    for (unsigned i = 0; i < g[v].size(); i++) {
      int u = g[v][i];
      if (u != p) {
        depth[u] = depth[v] + 1;
        dfs(u, v);
      }
    }
  };

  int ans = n;
  {
    for (int st = 0; st < n; st++) {
      int cnt = 0;
      depth[st] = 0;
      dfs(st, -1);
      for (int i = 0; i < n; i++) {
        if (2 * depth[i] > K) {
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  {
    for (int eid = 0; eid < n - 1; eid++) {
      int v = vv[eid];
      int u = uu[eid];
      depth[v] = depth[u] = 0;
      dfs(v, u);
      dfs(u, v);
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (2 * depth[i] + 1 > K) {
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int main ()
{
    int A = 0, B = 0;

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

    A += (a-'0') * 10;
    A += (b-'0');


    B += (c-'0') * 10;
    B += (d-'0');

    if (A <= 12 && A > 0) //A definitivamente é mês
    {
        if (B <= 12 && B > 0)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "MMYY" << endl;
    } else if (B <= 12 && B > 0)
    {
        if (A <= 12 && A > 0)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "YYMM" << endl;
    } else
        cout << "NA" << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int a[N], b[N];
int main() {
    int n;
    cin >> n;
    int ok = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (i >= 3) {
            if (a[i - 1] == b[i - 1] && a[i] == b[i] && a[i - 2] == b[i - 2]) ok = 1;
        }
    }
    puts(ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3636
N = gets.to_i
S = gets.chomp
arr1 = Array.new(N+1,0)
arr2 = Array.new(N+1,0)
arr = Array.new(N+1,0)

for i in 0..N do
  if i == 0
    arr1[i] = 0
  elsif S[i-1] == "W"
    arr1[i] = arr1[i-1] + 1
  else
    arr1[i] = arr1[i-1]
  end
  arr[i] += arr1[i]
  j = N - i
  if j == N
    arr2[j] = 0
  elsif S[j] == "E"
    arr2[j] = arr2[j+1] + 1
  else
    arr2[j] = arr2[j+1]
  end
  arr[j] += arr2[j]
end

puts arr.min


Measured memory_bytes: 9492
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int H, W;
    cin >> H >> W;
    vector<string> s;
    string str;
    for (int i = 0; i < H; i++)
    {
        cin >> str;
        s.emplace_back(str);
    }

    int pi[4] = {-1,  0, +1,  0};
    int pj[4] = { 0, -1,  0, +1};
    int cnt;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            bool ok = false;
            if (s[i][j] == '#')
            {
                for (int k = 0; k < 4; k++)
                {
                    if (i + pi[k] < 0 || i + pi[k] > H - 1) continue;
                    if (j + pj[k] < 0 || j + pj[k] > W - 1) continue;
                    if (s[i + pi[k]][j + pj[k]] == '#')
                    {
                        ok = true;
                    }

                }
                if (!ok)
                {
                    cout << "No" << endl;
                    return 0;
                }
                
            }
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var x = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        if (nm[0] >= nm[1]) { WriteLine(0);return; }
        Array.Sort(x);
        var dif = new long[nm[1] - 1];
        for(var i = 1; i < nm[1]; i++)
        {
            dif[i-1] = x[i] - x[i - 1];
        }
        Array.Sort(dif);
        var sum = 0L;
        for (var i = 0; i < nm[1] - nm[0]; i++)
            sum += dif[i];
        WriteLine(sum);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 17248
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String S = sc.nextLine();
    char c = S.charAt(0);
    int count = 1;
    int ans = 0;
    for(int i = 1; i < S.length(); i++){
      if(count == 0){
        c = S.charAt(i);
        count++;
      }else if(c == S.charAt(i)){
        count++;
      }else{
        count--;
        ans += 2;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 26296
#include <iostream>
#include <sstream>
#include <string>
#include <bitset>
#include <cmath>
using namespace std;

string a[128];

void init() {a[' ']="101";    a['\'']="000000";    a[',']="000011";    a['-']="10010001";    a['.']="010001";    a['?']="000001";    a['A']="100101";    a['B']="10011010";    a['C']="0101";    a['D']="0001";    a['E']="110";    a['F']="01001";    a['G']="10011011";    a['H']="010000";    a['I']="0111";    a['J']="10011000";    a['K']="0110";    a['L']="00100";    a['M']="10011001";    a['N']="10011110";    a['O']="00101";    a['P']="111";    a['Q']="10011111";    a['R']="1000";    a['S']="00110";    a['T']="00111";    a['U']="10011100";    a['V']="10011101";    a['W']="000010";    a['X']="10010010";    a['Y']="10010011";    a['Z']="10010000";}

int main() {
  init();
  
  string s;
  while( getline(cin, s) ) {
    stringstream ss;
    
    for(int i=0; i<s.size(); i++) ss << a[s[i]];
    
    string str = ss.str();
    
    while( str.size()%5 ) str += '0';
    
    for(int i=0; i<str.size(); i+=5) {
      int b = bitset<5>(str.substr(i,5)).to_ulong();
      if( b <= 25 ) cout << (char)(b+'A');
      else if( b == 26 ) cout << ' ';
      else if( b == 27 ) cout << '.';
      else if( b == 28 ) cout << ',';
      else if( b == 29 ) cout << '-';
      else if( b == 30 ) cout << '\'';
      else cout << '?';
    }
    
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1196
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))


abc = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()

string = rls()
ans = 114514810931

for j in abc:
    s = string[:]
    count = 0
    if(len(set(s)) == 1):
        ans = 0
        break
    while(count <= 10000):
        t = []
        count += 1
        for i in range(len(s)-1):
            if(s[i] == j or s[i+1] == j):
                t.append(j)
            else:
                t.append(s[i])
        if(set(t) == {j}):
            ans = min(ans, count)
            break
        elif(set(t) == set()):
            break
        s = t[:]

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);

    ll k, n;
    cin >> k >> n;

    vll a(n);

    for0(i, n){
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    vll diff(n);

    for0(i, n - 1){
        diff[i] = a[i + 1] - a[i];
    }
    diff[n - 1] = k - a[n - 1] + a[0];

    cout << k - *max_element(diff.begin(), diff.end());

    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
int n,h[3],p[5],i;
int main()
{
	for(;scanf("%d",&p[0]),p[0];)
	{
		h[0]=h[1]=h[2]=0;
		for(h[p[0]%3]++,i=1;i<5;h[p[i++]%3]++)
			scanf("%d",&p[i]);
		for(i=0;i<3;i++)
			if(h[i%3]<5&&h[(i+1)%3]<5&&h[i%3]+h[(i+1)%3]==5)
			{
				h[i%3]=1,h[(i+1)%3]=2;break;
			}
		for(n=0;n<5;n++)
			printf("%d\n",i==3?3:h[p[n]%3]);
	}
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    long double n,x,y, k;
    cin >> n>>k>>x>>y;
    int ans = min(n, k)*x+(n-min(n,k))*y;
  cout<<ans<<endl;

    return 0;
}


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

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(sc.hasNext()){
            int n = Integer.parseInt(sc.next());
            if(n==0) break;
            
            int sum = 0;
            int[] data = new int[n];
            for(int i=0; i<n; i++){
                data[i] = Integer.parseInt(sc.next());
                sum += data[i];
            }
            double mean = (double)sum / n;
            
            double vars=0.0;
            for(int i=0; i<n; i++){
                vars += Math.pow((data[i] - mean),2.0);
            }
            double std = Math.sqrt(vars / n);
            System.out.println(std);
        }
    }
}



Measured memory_bytes: 31920
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;
int a[111111];
int b[111111];
int c[111111];

/*
*/
int binary_search_a(int num);
/*
*/
int binary_search_c(int num);

int main() {
	ios_base::sync_with_stdio(false);

	long long ans = 0;

	cin >> n;
	for (int i = 0; i<n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i<n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i<n; i++) {
		cin >> c[i];
	}

	sort(a, a + n);
	sort(c, c + n);

	for (int i = 0; i<n; i++) {
		long long aa = lower_bound(a, a + n, b[i]) - a;
		long long cc = (c+n) - upper_bound(c, c + n, b[i]);
		ans += aa * cc;
	}

	cout << ans << endl;

	return 0;
}

int binary_search_a(int num) {
	int ng = -1;
	int ok = n;
	int mid = abs(ok - ng);

	while (abs(ok - ng) > 1) {
		mid = (ok + ng) / 2;
		if (num <= a[mid]) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	return ok;
}

int binary_search_c(int num) {
	int ng = -1;
	int ok = n;
	int mid = abs(ok - ng);

	while (abs(ok - ng) > 1) {
		mid = (ok + ng) / 2;
		if (num < c[mid]) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	return (n - ok);
}


Measured memory_bytes: 1664
#ABC090C
N, M=map(int, input().split())
ans=0
if N*M==1:
    ans=1
elif N*M==2:
    ans=0
elif N==1 or M==1:
    ans=N*M-2
elif N==2 or M==2:
    ans=0
else:
    ans=(N-2)*(M-2)
print(ans)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  
  string ans = "x";
  if (a + b == 15) {
    ans = "+";
  }
  if (a * b == 15) {
    ans = "*";
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3584
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var ans = 0L;
            for (long i = 1; i <= N - 1; i++)
            {
                ans += i;
            }
            WriteLine(ans);
        }



        public long C(int X, int Y)
        {

            if (Y == 0 || Y == X)
            {
                return 1;
            }
            if (X < Y)
            {
                return 0;
            }
            var Pascal = new long[X + 1, X + 1];
            for (int i = 0; i <= X; i++)
            {
                Pascal[i, 0] = 1L;
                Pascal[i, i] = 1L;
            }
            for (int i = 2; i <= X; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[X, Y];
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int ans[];
	static int count = 0;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split("");

		if (str[2].equals(str[3]) && str[4].equals(str[5])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  rep (i, M) cin >> s[i] >> c[i];
  string str;
  
  if (N==1) str = "0";
  else str = "1";
  rep(i, N-1) str += '0';
  rep(i, M) str[s[i]-1] = c[i];
  
  if(N>=2) {
    rep(i, M) if(s[i]==1 && c[i]=='0') str = "-1";
  }
  rep(i, M){
    rep(j, M-1-i) if(s[i]==s[i+j+1] && c[i]!=c[i+j+1]) str = "-1";
  }
  
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    rep(i, n / 4 + 1) {
        rep(j, n / 7 + 1) {
            if (4 * i + 7 * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
l,r = int(S[:2]),int(S[2:])
if 1 <= l <= 12 and 1 <= r <= 12:
	print("AMBIGUOUS")
elif 1<=r<=12:
	print("YYMM")
elif 1<=l<=12:
	print("MMYY")
else:
	print("NA")

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

using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, c; cin >> a >> b >> c;
	if((a+b+c) % 17 == 0) {
		cout << "YES";
		return 0;
	}
	cout << "NO";
	return 0;
} 
 


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int  main(){
	int a,b,c;
	scanf("%d/%d/%d",&a,&b,&c);
	getchar();
	if(b>4) 
		puts("TBD");
	else   
		puts("Heisei"); 
	return 0;
}

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

int main() {
    int x;
    int i = 1;
    while(cin >> x) {
        if(x == 0) {
            break;
        }
        else {
            cout << "Case " << i << ": " << x << endl;
            i++;
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 3088
import io.StdIn.readInt
object Main extends App {
  val n = readInt
  val ss = Seq.fill(n)(readInt)
  println(solve(ss))
  def solve(ss: Seq[Int]) = {
    val all = ss.sum
    val sub = ss.filter(_ % 10 != 0)
    if (all % 10 != 0) all
    else if (!sub.isEmpty) all - sub.min
    else 0
  }
}


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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7; 
const int N = 1e4+10; 
const int INF = 1e9 + 5; 



int d[N];
int main(void) 
{
	
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif
	
	int h, n; 
	scanf("%d %d", &h, &n); 
	for (int i=0; i<=h; i++) d[i] = INF; 
	d[0]=0; 
	while (n--) 
	{
		int value, cost; 
		scanf("%d %d", &value, &cost); 
		for (int i=0; i<=h; ++i) 
		{
			int j = min(h, i+value); 
			d[j] = min(d[j], d[i] + cost); 
		}
	}
	printf("%d\n", d[h]); 



	return false;   


}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long int x, sum;
  int count = 0;

  cin >> x;
  sum = 100;
  while(true){
    count = count + 1;
    sum += sum*0.01;
    if(sum >= x){
      cout << count << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  val lastFound= Array.tabulate(2 * 100000){_ ⇒ -1}
  val next = Array.tabulate(n){_ ⇒ 0}
  val colors = Array.tabulate(n){_ ⇒ readInt - 1}
  for (i ← colors.indices.reverse){
    next(i) = lastFound(colors(i))
    lastFound(colors(i)) = i
  }
  val memo = Array.tabulate(n){_ ⇒ -1L}
  val mod = 1000000007L
  for (i ← memo.indices.reverse) solve(i, memo)
  println(
    solve(0, memo)
  )

  def solve(position: Int, memo: Array[Long]): Long = {
    if (position < memo.length){
      if (memo(position) == -1){
        memo(position) = 0
        if (next(position) != -1 && next(position) != position + 1) {
          memo(position) += solve(next(position), memo)
        }
        memo(position) += solve(position + 1, memo)
      }
      memo(position) %= mod
      memo(position)
    }else 1L
  }
}

Measured memory_bytes: 46096
S = list(map(int, input()))
L = len(S)
mod = 2019
T = []
A = [0 for i in range(mod)]
t = 0
p = 1
for i in range(L-1, -1, -1):
  t = (t + S[i] * p) % mod
  A[t] += 1
  p = (p * 10) % mod
print(A[0] + sum([a * (a-1) // 2 for a in A]))

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

int main() {
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++) {
        if(i%k==0) {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
int main(){
    int a,b,n;
    while(scanf("%d%d%d",&a,&b,&n)!=-1){
        int sum=0;
        a%=b;
        for(int i=1;i<=n;i++){
            a*=10;
            sum+=a/b;
            a%=b;
        }
        printf("%d\n",sum);
    }
}

Measured memory_bytes: 0
eval'N,M,A,*B='+`dd`.split*?,
s=[c=d=x=0]*9*M
B.map{|b|e=b;A>b&&b+=M;x+=t=b-A
[0,M].map{|m|s[m-~A]+=1;s[m+b]-=t;s[m-~b]+=t-1}
A=e}
p x-s.map{|s|d+=c+=s}.max

Measured memory_bytes: 48976
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int parent(int v) {
	return v / 2;
}

int left(int v) {
	return v * 2;
}

int right(int v) {
	return v * 2 + 1;
}

void print_heap(vector<int> heap, int H) {
	for (int i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << heap[i] << ", ";
		if (parent(i) >= 1) cout << "parent key = " << heap[parent(i)] << ", ";
		if (left(i) <= H) cout << "left key = " << heap[left(i)] << ", ";
		if (right(i) <= H) cout << "right key = " << heap[right(i)] << ", ";
		cout << endl;
	}
}

int main() {
	int H;
	cin >> H;
	vector<int> heap(H + 1);
	for (int i = 1; i <= H; i++) cin >> heap[i];
	print_heap(heap, H);
	return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#define MAX_DATASETS 200

int count_digits(int x) {
    int count = 1;

    while (x /= 10) {
	count++;
    }
    return count;
}

int main(void) {
    int a[MAX_DATASETS], b[MAX_DATASETS], i=0,j;

    while (scanf("%d %d", &a[i], &b[i]) != EOF) {
	i++;
    }
    for (j = 0; j < i; j++) {
	printf("%d\n", count_digits(a[j]+b[j]));
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef int ll;
using namespace std;
int32_t main(){
	#ifndef ONLINE_JUDGE
    	// for getting input from input.txt
    	freopen("input.txt", "r", stdin);
    	// for writing output to output.txt
    	freopen("output.txt", "w", stdout);
    	// for debug in error.txt
    	freopen("error.txt", "w", stderr);
	#endif
	int t = 1;
	while(t--) {
		ll a, b, c, k;
		cin >> a >> b >> c >> k;
		bool ok = false;
		if(a < b) {
			if(b < c) {
				ok = true;
			} else if(b < (2*k*c)) {
				ok = true;
			}
		} else {
			ll cnt = 0;
			while(a >= b) {
				b = b*2;
				cnt++;
			}
			while(b >= c) {
				c = c*2;
				cnt++;
			}
			if(cnt <= k) {
				ok = true;
			}
		}
		if(ok) {
			cout << "Yes" << '\n';
		}else {
			cout << "No" << '\n';
		}
	}
}

Measured memory_bytes: 3504
S = gets.chomp.split('')

S.each_with_index do |char, i|
  if (i+1) % 2 == 0
    if char == "R"
      puts "No"
      exit
    end
  else
    if char == "L"
      puts "No"
      exit
    end
  end
end

puts "Yes"

Measured memory_bytes: 1788
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,x;
int a[10011];
int main()
{
	getii(n,x);
	for(int i=1;i<=n;i++)
	{
		geti(a[i]);
	}
	sort(a+1,a+n+1);
	ll sum=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		sum+=a[i];
		if(sum<=x)
		{
			ans=i;
		}
	}
	if(ans==n&&sum!=x)cout<<ans-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

ll N, C;

ll solve(vector<ll> &x, vector<ll> &v){
    vector<ll> f(100100), mf(100100), g(100100);
    f[0] = 0;
    ll v_sum = 0;
    REP(i, N){
        v_sum += v[i];
        f[i+1] = v_sum - x[i];
    }
    ll tmp_max = -1;
    REP(i, N+1){
        tmp_max = max(tmp_max, f[i]);
        mf[i] = tmp_max;
    }
    g[0] = 0;
    ll v_sum2 = 0;
    REP(i, N+1){
        v_sum2 += v[N-1-i];
        g[i+1] = v_sum2 - 2*(C-x[N-1-i]);
    }
    ll res = -1;
    REP(i, N+1){
        res = max(res, mf[i] + g[N-i]);
    }

    return res;
}

int main(){
    cin >> N >> C;
    vector<ll> x(100100), v(1000100), xr(100100), vr(100100);
    REP(i, N) cin >> x[i] >> v[i];
    REP(i, N){
        xr[i] = C - x[N-1-i];
        vr[i] = v[N-1-i];
    }
    cout << max(solve(x, v), solve(xr, vr)) << endl;
    return 0;
}

Measured memory_bytes: 12800
/*
	Author: zxy_hhhh
	date: 2019/11/28
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
#define ll long long
inline ll rd() {
	ll _x=0;int _ch=getchar(),_f=1;
	for(;!isdigit(_ch)&&(_ch!='-')&&(_ch!=EOF);_ch=getchar());
	if (_ch=='-'){_f=0;_ch=getchar();}
	for(;isdigit(_ch);_ch=getchar()) _x=_x*10+_ch-'0';
	return _f?_x:-_x;
}
void write(ll _x){if (_x>=10) write(_x/10),putchar(_x%10+'0'); else putchar(_x+'0'); }
inline void wrt(ll _x,char _p){if (_x<0) putchar('-'),_x=-_x; write(_x); if (_p) putchar(_p);}
#define maxn 1000005
#define mod 1000000007
int dp[maxn][3];
int fac[maxn],inv[maxn],Inv[maxn];
int n;
inline int C(int n,int m) {return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int qpow(int x,int k) {
	int ans=1;
	for(;k;k>>=1,x=1ll*x*x%mod) if (k&1)
		ans=1ll*ans*x%mod;
	return ans;
}
int main() {
	n=rd();
	fac[0]=fac[1]=inv[0]=inv[1]=Inv[0]=Inv[1]=1;
	for(int i=2;i<=n+1;i++) {
		fac[i]=1ll*fac[i-1]*i%mod;
		Inv[i]=1ll*(mod-mod/i)*Inv[mod%i]%mod;
		inv[i]=1ll*inv[i-1]*Inv[i]%mod;
	}
	dp[1][0]=1;
	for(int i=2;i<=n+1;i++) {
		dp[i][0]=(dp[i-1][1]+dp[i-1][2])%mod;
		dp[i][1]=(dp[i-1][0]+dp[i-1][2])%mod;
		dp[i][2]=(dp[i-1][0]+dp[i-1][1])%mod;
	}
	int x=qpow(3*n,mod-2);

	int ans=0;
	for(int k=1;k<=n;k++) {
		int P1=dp[k+1][1],P2=C(n,k);
		int P=1ll*P1*P2%mod;
		int L=1ll*x*Inv[k]%mod;
		// printf("%d/%d\n",P,3*n*k);
		// printf("%d\n",3*n*k);
		ans=(ans+1ll*L*P)%mod;
	}
	wrt(1ll*ans*qpow(qpow(3,n-1),mod-2)%mod,'\n');
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	while(1){
		ll N,M; cin >> N >> M;
		if(N==0 && M == 0) return 0;
		V<ll> P(N+1,0), X;
		for(int i = 1; i <= N; ++i) cin >> P[i];
		for(int i = 0; i <= N; ++i) for(int j = i; j <= N; ++j)	X.push_back(P[i]+P[j]);
		sort(ALL(X));
		ll ans = 0;
		for(auto e:X){
			if(e>M) continue;
			ll c = *--upper_bound(ALL(X),M-e);
			chmax(ans,c+e);
		}
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 10652
# ABC155
# B Papers,Please
n = int(input())
a = list(map(int, input().split()))
ans = 0
ant = 0
b = []
for i in range(n):
    if a[i] % 2 == 0:
        ant += 1
        b.append(int(a[i]))
        if a[i] % 3 == 0:
            ans += 1
        elif a[i] % 5 == 0:
            ans += 1

if ant == ans:
    if ant > 0:
        print("APPROVED")
    else:
        print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 9156