akhauriyash/Code-Regression huggingface dataset:
'''
import random

random.seed(1000)

D = 365
cs = [random.randrange(0, 101) for _ in range(26)]
ss = [[random.randrange(0, 20001) for _ in range(26)] for _ in range(D)]

'''
D = int(input())
cs = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(D)]
#'''
width = 22

def calc(ts):
    last = [-1] * 26
    sat = 0
    for i, t in enumerate(ts):
        sat += ss[i][t-1]
        last[t-1] = i
        sat -= sum(c * (i - l) for c, l in zip(cs, last))       
    return sat

def search(ts):
    last = [-1] * 26
    sat = 0
    for i, t in enumerate(ts):
        sat += ss[i][t-1]
        last[t-1] = i
        sat -= sum(c * (i - l) for c, l in zip(cs, last))
    
    deltas = [-(10 ** 9)]
    i = len(ts)
    for t in range(1, 27):
        tmp = last[t-1]
        last[t-1] = i
        delta = ss[i][t-1] - sum(c * (i - l) for c, l in zip(cs, last))
        last[t-1] = tmp
        deltas.append(sat + delta)

    ls = sorted(enumerate(deltas), key = lambda t: t[1], reverse = True)
    return ls[:width]

#ビームサーチのつもり
best5ts = [[]]
for i in range(D):
    possible_best5ts = []
    possible_sats = []
    for ts in best5ts:
        best5t, sats = map(list, zip(*search(ts)))
        possible_best5ts += [ts + [t] for t in best5t]
        possible_sats += sats
    ls = sorted(enumerate(possible_sats), key = lambda t: t[1], reverse = True)
    best5ts = []
    for i, _ in ls[:width]:
        best5ts.append(possible_best5ts[i])

ts = best5ts[0]

print(*ts, sep = '\n')
#print(calc(ts) + 365 * 10 ** 6)


Measured memory_bytes: 173620
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
using namespace std;

string S="##########################################################################################################################################################################################################################";
signed main(){
	int a,b;cin>>a>>b;
	string c[102];
	c[0]=c[a+1]=S.substr(0,b+2);
	for(int d=0;d<a;d++){
		c[d+1]="#";
		string e;cin>>e;
		c[d+1]+=e;
		c[d+1]+="#";
		}
	for(int i=0;i<a+2;i++)cout<<c[i]<<endl;	
	}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int t[100010];

int main(void){
	          int i;

	          int N,M;
	          cin >> N >> M;
	          for(i=1;i<=M;i++){
	        	  int a,b;
	        	  cin >> a >> b;
	        	  t[a]++; t[b]--;
	          }

	          for(i=2;i<N;i++){
	        	  t[i]=t[i]+t[i-1];
	          }

	          for(i=1;i<N;i++){
	        	  if(t[i]%2==1){
	        		  cout << "NO" << endl;

	        		  return 0;
	        	  }
	          }

	          cout << "YES" << endl;

	          return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,j,k,ans=0;
  cin>>n>>m;
  int x[n],y[m];
  memset(y,0,sizeof(y));
  map<int,int> mi;
  for(i=0;i<n;i++){
    cin>>x[i];
    mi[x[i]]++;
    y[x[i]%m]++;
  }
  ans+=y[0]/2;
  y[0]%=2;
  if(m%2==0){
    ans+=y[m/2]/2;
    y[m/2]%=2;
  }
  for(i=1;i<m;i++){
    if(i*2==m) continue;
    k=min(y[i],y[m-i]);
    ans+=k;
    y[i]-=k;
    y[m-i]-=k;
    //cout << i << ":" << k << ":" << ans << endl;
  }
  for(i=0;i<n;i++) {
    k=min(y[x[i]%m],mi[x[i]])/2;
    if(k>0){
      ans+=k;
      y[x[i]%m]-=k*2;
      mi[x[i]]-=k*2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 998244353;

ll c[112345];
ll A[112345];
bool used[112345];
int root=-1;
bool dfs(const vector<vint>& g,int u){
  used[u] = true;
  ll sum = 0;
  ll maxc = 0;
  for(int v:g[u]){
    if(used[v]) continue;
    if(!dfs(g,v)) return false;
    sum += c[v];
    maxc = max(maxc,c[v]);
  }
  if(u==root){
    cerr << "!!!!!!!!" << endl;
    debug(sum);
    return A[u]==sum;
  }
  if(g[u].size()==1){
    c[u] = A[u];
    return true;
  }
  ll T = c[u] = 2*A[u]-sum;
  if(T<0 || sum < T) return false;
  ll L = (sum-T)/2;
  /*
  debug(u);
  debug(sum);
  debug(T);
  debug(L);
  */
  return L<=min(sum-maxc,sum/2);
}

int main() {
  int N;cin >> N;
  repeat(i,N) cin >> A[i];
  vector<vint> g(N);
  repeat(i,N-1){
    int a,b;cin >> a >> b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  repeat(i,N){
    if(root<0&&g[i].size()==1){
      root = i;
    }
  }
  cout << (dfs(g,root)? "YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 18304
from functools import lru_cache

X, Y, A, B, C = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
best = sum(red) + sum(green)

for x in R:
    smaller = None
    if not red and not red:
        break
    elif red and green:
        if red[-1] < green[-1]:
            smaller = red
        else:
            smaller = green
    elif red:
        smaller = red
    elif green:
        smaller = green
    else:
        assert False

    if smaller[-1] < x:
        best -= smaller.pop()
        best += x
print(best)


Measured memory_bytes: 104676
datas = $stdin.read.split("\n")
n = datas[0].to_i
a = datas[1].split(" ")
a.map! do |x|
  x.to_i
end
max = 0
min = 10 ** 10
for i in 0..a.count - 1 do
  max = a[i] if max < a[i]
  min = a[i] if min > a[i]
end
puts max - min

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), c[1000];
    rep (i, m) {
        int b; cin >> a[i] >> b;
        rep (j, b) {
            int d; cin >> d;
            c[i].push_back(d - 1);
        }
    }
    int dp[1001][4096], MAX = 10000000;
    rep (i, m + 1) rep (j, 1 << n) dp[i][j] = MAX;
    dp[0][0] = 0;
    rep (i, m) {
        int bits = 0;
        for (int j: c[i]) bits |= (1 << j);
        eprintf("%d\n", bits);
        rep (j, 1 << n) dp[i + 1][j] = dp[i][j];
        rep (j, 1 << n) chmin(dp[i + 1][j | bits], dp[i][j] + a[i]);
    }
    rep (i, m + 1) {
        rep (j, 1 << n) {
            if (dp[i][j] == MAX) eprintf("- ");
            else eprintf("%d ", dp[i][j]);
        }
        eprintf("\n");
    }
    if (dp[m][(1 << n) - 1] == MAX) cout << "-1\n";
    else cout << dp[m][(1 << n) - 1] << "\n";
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


ll N,Np, S[303030];
priority_queue<ll> aaq;
stack<ll> as,bs;
vector<ll> av;
ll i, j, k,ans;

int main(){
    scanf("%lld",&N);
    Np = 1 << N;
    fornum(i,0,Np){
        scanf("%lld", &S[i]);
    }
    sort(S, S + Np);
    //printf("s");
    fornum(i,0,Np){
        as.push(S[i]);
    }
    av.push_back(as.top());
    as.pop();

    fornum(i,0,N){
        //printf("%d\n", as.size());
        sort(av.begin(), av.end(),greater<ll>());
        fornum(j,0,(1<<i)){
            if(as.empty()){
                break;
            }
            ll a = as.top();
            as.pop();
            if(av[j]>a){
                av.push_back(a);
            }else{
                bs.push(a);
                j--;
            }
        }
        if(j<(1<<i)){
            break;
        }
        while(bs.size()){
            as.push(bs.top());
            bs.pop();
        }
    }
    printf("%s", i == N ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 7668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.max(a+b, Math.max(a-b, a*b)));

	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	long double ans = 0; 
	for(int i = 0; i < n; i++){
		double a;
		string s;
		cin >> a >> s;
		if(s[0] == 'J')
			ans += a;
		else
			ans += (a * 380000);
	}
	cout << ans;
}

Measured memory_bytes: 256
import queue
q = queue.Queue()
n = int(input())
cnt = 0
q.put(3)
q.put(5)
q.put(7)
while not q.empty():
    tmp = q.get()
    if tmp <= n:
        if ('3' in str(tmp)) and ('7' in str(tmp)) and ('5' in str(tmp)):
            cnt += 1
        q.put(tmp*10 + 3)
        q.put(tmp*10 + 5)
        q.put(tmp*10 + 7)
    else:
        continue
print(cnt)
        

Measured memory_bytes: 6640
#include <iostream>
#include <algorithm>

int main() {
	int x[2] = {1,1}, i = 1;
	while (1) {
		std::cin >> x[0] >> x[1];

		if (x[0] + x[1] != 0) {
			if (x[0] < x[1]) {
				std::cout << x[0] << " " << x[1] << std::endl;
			}
			else {
				std::cout << x[1] << " " << x[0] << std::endl;
			}
		}
		if (x[0] == 0 && x[1] == 0)break;
	}
 }


Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int a, b; cin >> a >> b;
	cout << max({a+b, a-b, a*b}) << endl;
	return 0;
}

Measured memory_bytes: 256
// Date: 2020-03-13

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int dp[N][3], a[N][3], n;

int main() {
    FIO;
    cin >> n;
    rep(i, 1, n) rep(j, 0, 2) cin >> a[i][j];
    rep(j, 0, 2) dp[1][j] = a[1][j];
    rep(i, 2, n) {
        rep(j, 0, 2) rep(k, 0, 2) {
            if(k != j) chkmax(dp[i][j], dp[i-1][k] + a[i][j]);
        }
    }
    int ans = 0;
    rep(i, 0, 2) chkmax(ans, dp[n][i]);
    cout << ans;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> student_list(N, make_pair(0, 0));
	for (int i = 0; i < N; i++)
	{
		cin >> student_list[i].first >> student_list[i].second;
	}

	vector<pair<int, int>> point_list(M, make_pair(0, 0));
	for (int i = 0; i < M; i++)
	{
		cin >> point_list[i].first >> point_list[i].second;
	}

	for (int i = 0; i < N; i++)
	{
		pair<int, int> min_result = make_pair(1e9, -1);
		for (int j = 0; j < M; j++)
		{
			int dist = abs(student_list[i].first - point_list[j].first) + abs(student_list[i].second - point_list[j].second);
			if (dist < min_result.first)
			{
				min_result = make_pair(dist, j);
			}
		}

		cout << min_result.second + 1 << "\n";;
	}

	return 0;
}


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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b - c) <= d) || (abs(a - c) <= d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL N, LL T, vector<LL> c, vector<LL> t){
	LL min = 1001, argmin = -1;
	REP(i, N) {
		if (t[i] > T) {
			continue;
		}
		if (c[i] < min) {
			min = c[i];
			argmin = i;
		}
	}
	if (argmin != -1) {
		cout << min << endl;
	} else {
		cout << "TLE" << endl;
	}
}


int main(){	
	LL T;
	LL N;
	scanf("%lld",&N);
	vector<LL> t(N-1+1);
	vector<LL> c(N-1+1);
	scanf("%lld",&T);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&c[i]);
		scanf("%lld",&t[i]);
	}
	solve(N, T, c, t);
	return 0;
}



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

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

  int a, b;
  cin >> a >> b;
  if (a <= 8 && b <= 8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}


Measured memory_bytes: 256
N = int(input())
L = sorted(map(int, input().split()), reverse=True)
cnt = 0

for i in range(N - 2):
    c = L[i]
    
    for j in range(i + 1, N - 1):
        b = L[j]
        l = j
        r = N - 1
        
        while True:
            idx = -(-(l + r) // 2)
            
            if L[idx] > c - b:
                if l == idx:
                    break
                l = idx
            else:
                if r == idx:
                    break
                r = idx
                
        cnt += l - j
        
print(cnt)

Measured memory_bytes: 43372
#include<bits/stdc++.h>
    using namespace std;
    #define inp(k)           ll k;cin>>k;
    #define in2(n,k)       ll n, k; cin>>n;cin>>k;
    #define in3(n,k,r)       ll n, k,r; cin>>n;cin>>k;cin>>r;
    #define ll long long
    #define dl double
    #define ch char
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define rf(i,a,b) for(ll i=a-1;i>=b;i--)
    #define Godspeed                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define vpl vector< pair<ll,ll> >
    #define vpi vector< pair<int,int> >
    #define vi vector<int>
    #define vl vector<ll>
    #define vdl vector<dl>
    #define vch vector<char>
    #define pll pair<ll,ll>
    #define pb push_back
    #define mp make_pair
    #define fr first
    #define se second
    #define PI 3.14159265
    /*vl v[10005];
    ll cnt=0;
    ll a[51][51]={0};
    bool visited[10005]={0};
    void dfs(ll u)
    {
        visited[u]=1;
        f(i,0,v[u].size())
        {
            ll f=v[u][i];
            if(!visited[f])
            {
                dfs(f);
            }
        }
    }*/
    #define INF 1000000005
    void solve()
    {
        string s,t;cin>>s>>t;string p="";
        ll n=s.length(),m=t.length();
        ll dp[n+1][m+1];f(i,0,n+1)dp[i][0]=0;f(i,0,m+1)dp[0][i]=0;
        f(i,1,n+1)
        {
            f(j,1,m+1)
            {
                if(s[i-1]==t[j-1])
                {
                    dp[i][j]=1+dp[i-1][j-1];
                }
                else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }

        ll index=dp[n][m];
        char ans[index];ans[index]='\0';
        ll i=n,j=m;
        while(i&&j)
        {
            if(s[i-1]==t[j-1])
            {
                ans[index-1]=s[i-1];
                --i;--j;--index;
            }
            else if (dp[i-1][j]>dp[i][j-1])i--;
            else    j--;
        }
        cout<<ans;
    }

    int32_t main(void)
    {
        Godspeed;
        int q;
        q=1;
        //cin>>q;
        while (q--)
        {
            solve();cout<<endl;
        }
        return 0;
    }


Measured memory_bytes: 73976
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ar[] = new int[n];
    for(int i = 0;i<n;i++)
    {
      ar[i] = sc.nextInt();
    }
    boolean isComplete = true;
    for(int i = n-1;i>1;i--)
    {
      if(ar[i]>=ar[i-1])
      {
        continue;
      }
      ar[i-1]--;
      if(ar[i]>=ar[i-1]&&ar[i-1]>=0)
      {
        continue;
      }
      isComplete = false;
      break;
    }
    System.out.println(isComplete?"Yes":"No");
  }
}

Measured memory_bytes: 51356
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
    int N;
    cin>>N;
    char s1[N+1];
    char s2[N+1];
    s1[N] = '?';
    s2[N] = '?';
    REP(i,N){
        cin>>s1[i];
    }
    REP(i,N){
        cin>>s2[i];
    }

    INT ans = 3;
    int state[N];
    int cnt=0;
    int idx=0;
    while (idx < N){
        if (s1[idx] == s1[idx+1]){
            state[cnt] = 1;
            idx++;
        }else if(s1[idx] == s2[idx]){
            state[cnt] = 0;
        }
        cnt++;
        idx++;
    }
    int L = cnt;
    REP(i,L){
        if (state[i] == 1){
            if (i!=0 && state[i-1] == 1){
                ans *= 3;
                ans %= MOD;
            }else{
                ans *= 2;
                ans %= MOD;
            }
        }else{
            if (i == 0) continue;
            else if(state[i-1] == 0){
                ans *= 2;
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;\

    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <functional>
#include <cassert>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int K,N;
	scanf("%d%d", &K,&N);
	vector<int> A(N);
	rep(i, N)scanf("%d", &A[i]);
	sort(A.begin(), A.end());
	int maxa = A[N - 1] - A[0];
	maxa = min(maxa, K - maxa);
	rep(i, N-1)maxa = max(maxa, A[i + 1] - A[i]);
	printf("%d", K - maxa);
}

Measured memory_bytes: 4080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

int main(){
    int a,b,sum,keta;
    while(cin>>a>>b){
        sum=a+b;
        for(keta=1;;keta++){
            sum=sum/10;
            if(sum==0)break;
        }
        cout<<keta<<endl;
    }
    return 0;
}

Measured memory_bytes: 3012
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll MergeSort(vector<int>& A){
	int num = A.size();
	if(num<=1) return 0;

	ll cnt=0;
	vector<int> B(A.begin(),A.begin()+num/2);
	vector<int> C(A.begin()+num/2,A.end());

	cnt += MergeSort(B);
	cnt += MergeSort(C);

	int ai=0,bi=0,ci=0;
	int bnum=B.size(),cnum=C.size();
	while(ai<num){
		if(bi<bnum && (ci==cnum || B[bi]<=C[ci])){
			A[ai++] = B[bi++];
		} else {
			cnt += num/2-bi;
			A[ai++] = C[ci++];
		}
	}
	return cnt;
}

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

	while(true){
		ll N=in();
		if(!N) break;

		auto V=vecin(N);
		out(MergeSort(V));
	}
	
	return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
	//inp_out();
	ld a,b,c;
	cin>>a>>b>>c;
	if(a+b-c<(-2*(sqrt(a*b))))
	{
		cout<<"Yes";

	}
	else
	{
		cout<<"No";
	}
	return 0;
}



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

public class Main {

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

		while ((line = br.readLine()) != null) {
			if (line.length() > 1) {

				char[] nums = new char[10];
				int n, min, max;
				String minstr = "", maxstr = "";

				for (int i = 0; i < 8; i++) {
					n = Integer.parseInt(String.valueOf(line.charAt(i)));
					nums[n]++;
				}

				for (int i = 9; i >= 0; i--) {
					if (nums[i] > 0) {
						for (int j = 1; j <= nums[i]; j++) {
							maxstr += String.valueOf(i);
						}
					}
				}
				for (int i = 0; i < 10; i++) {
					if (nums[i] > 0) {
						for (int j = 1; j <= nums[i]; j++) {
							minstr += String.valueOf(i);
						}
					}
				}
				max = Integer.valueOf(maxstr);
				min = Integer.valueOf(minstr);
				System.out.println(max - min);
			}

		}
	}
}

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

int main(){
    int n;
    cin >> n;
    if(n%10 == 3){
        cout << "bon" << endl;
    }else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<queue>
#include<cstdio>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

int main(){
	for(int n,m,l;scanf("%d%d%d",&n,&m,&l),n;){
		int s=0,g=n-1;

		static int dis[100][100],cost[100][100];
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	dis[i][j]=(i==j?0:-1);
		for(int i=0;i<m;i++){
			int a,b,d,e;	scanf("%d%d%d%d",&a,&b,&d,&e);
			a--,b--;
			dis[a][b]=dis[b][a]=d;
			cost[a][b]=cost[b][a]=e;
		}

		static int cmin[100][101];
		for(int i=0;i<n;i++)for(int j=0;j<=l;j++)	cmin[i][j]=1<<30;

		int ans;
		priority_queue< pair<int,pii> > pq;	pq.push(mp(0,mp(s,l)));
		while(!pq.empty()){
			pair<int,pii> a=pq.top();	pq.pop();
			int nowcost=-a.first,u=a.second.first,bud=a.second.second;
			if(u==g){ ans=nowcost; break; }

			for(int v=0;v<n;v++){
				if(~dis[u][v]){
					int nextcost=nowcost+cost[u][v];
					int nextbud=bud;
					if(nextcost<cmin[v][nextbud]){
						pq.push(mp(-nextcost,mp(v,nextbud)));
						cmin[v][nextbud]=nextcost;
					}

					nextcost=nowcost;
					nextbud=bud-dis[u][v];
					if(nextbud<0)	continue;
					if(nextcost<cmin[v][nextbud]){
						pq.push(mp(-nextcost,mp(v,nextbud)));
						cmin[v][nextbud]=nextcost;
					}
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) (A)>(B)?(A):(B)
#define MIN(A,B) (A)<(B)?(A):(B)
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

typedef pair<int,int> pii;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << max(0, a-2*b);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define FOR(I, A, B) for (int I = int(A); I < int(B); ++I)

const int Q(2000010), N(6);
const int dir[8][2] = {{1, 1}, {-1, -1}, {-1, 1}, {1, -1}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n, t, x, y, s;
int q[Q], d[Q];
char str[N][N];
set<int> ha;

int state(int s, int x, int y) {
    return s * 25 + x * 5 + y;
}
void add(int s, int _d) {
    if (ha.count(s)) return;
    d[t] = _d; q[t++] = s; ha.insert(s);
}
int p(int x, int y) {return x * n + y;}
int bit(int x, int y) {
    return (x >> y) & 1;
}
int cnt(int ss, int x, int y) {
    int ret = 0;
    FOR(i, 0, 8) {
        int tx = x + dir[i][0], ty = y + dir[i][1];
        if (tx == -1 || ty == -1 || tx == n || ty == n) continue;
        ret += bit(ss, p(tx, ty));
    }
    return ret;
}
int bfs() {
    if (s == 0) return 0;
    FOR(h, 0, t) {
        y = q[h] % 5; x = q[h] % 25 / 5; s = q[h] / 25;
        FOR(i, 0, 8) {
            int tx = x + dir[i][0], ty = y + dir[i][1];
            if (tx == -1 || ty == -1 || tx == n || ty == n || bit(s, p(tx, ty))) continue;
            int ss = s | (1 << p(tx, ty)), ts = 0;
            FOR(j, 0, n)
                FOR(k, 0, n) {
                    int _cnt = cnt(ss, j, k);
                    if (bit(ss, p(j, k)) == 0) {
                        if (_cnt == 3) ts |= 1 << p(j, k);
                    }
                    else {
                        if (_cnt == 2 || _cnt == 3) ts |= 1 << p(j, k);
                    }
                }
            if (bit(ts, p(tx, ty))) ts -= 1 << p(tx, ty);
            if (ts == 0) return d[h] + 1;
            add(state(ts, tx, ty), d[h] + 1);
        }
    }
    return -1;
}
int main() {
    while (scanf("%d", &n), n) {
        ha.clear();
        FOR(i, 0, n)
            scanf("%s", str[i]);
        t = s = 0;
        FOR(i, 0, n)
            FOR(j, 0, n)
                if (str[i][j] == '@') {
                    x = i; y = j;
                }
                else if (str[i][j] == '#') s |= 1 << p(i, j);
        add(state(s, x, y), 0);
        printf("%d\n", bfs());
    }
    return 0;
}

Measured memory_bytes: 3504
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=3333;
int a[N][N];
ll f[N][N][4];
int n,m,k;
int main(){
	int x,y,v;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1; i<=k; i++){
		scanf("%d%d%d",&x,&y,&v);
		a[x][y]=v;		
	}
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++){
			for (int k=0; k<=3; k++){
				if (k)	f[i][j][k]=max(f[i][j][k],f[i][j-1][k-1]+a[i][j]);
				f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
			}
			for (int k=0; k<=3; k++){
				f[i][j][0]=max(f[i][j][0],f[i-1][j][k]);
				f[i][j][1]=max(f[i][j][1],f[i-1][j][k]+a[i][j]);
			}
		}
	ll ans=0;
	for (int i=0; i<=3; i++)
		ans=max(ans,f[n][m][i]);
	printf("%lld\n",ans);
    return 0;
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;
void dfs(vector<int> A){
    if(A.size() ==  n + 1) {
        int score = 0;
        rep(i,q){
            if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
        }
        ans = max(ans, score);
        return;
    }
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}
signed main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q){
        cin  >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>

using namespace std;
typedef long long ll;

ll ABS(ll a) {
	if (a < 0)return -a;
	else return a;
}
int main() {
	ll x, y;
	cin >> x >> y;
	ll ans=0;
	if (ABS(y) < ABS(x)) {
		if (x > 0)ans++;
		ans += (ABS(x) - ABS(y));
		if (y > 0)ans++;
	}
	else {
		if (x < 0)ans++;
		ans += ABS(y) - ABS(x);
		if (y < 0)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll l,r,d;
    cin>>l>>r>>d;
    cout<<(r/d)-(l-1)/d<<"\n";
}


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

const int mod = 1e9 + 7;

bool vis[64][2][2][2];
long long f[64][2][2][2];
bool Llimit[64], Rlimit[64];

long long dp(int k, bool Ltouch, bool Rtouch, bool first_bit) {
    if (k == -1) return 1;
    if (vis[k][Ltouch][Rtouch][first_bit]) return f[k][Ltouch][Rtouch][first_bit];
    vis[k][Ltouch][Rtouch][first_bit] = true;

    long long &rt = f[k][Ltouch][Rtouch][first_bit];

    // all one. 
    if (!(Rtouch && Rlimit[k] == 0)) {
        bool new_Ltouch = Ltouch;
        if (Llimit[k] == 0) new_Ltouch = false;
        
        // if (k == 1 && Llimit == false && Rlimit == true && first_bit == true) cout << new_Ltouch << ' ' << Rtouch << endl;
        rt = (rt + dp(k - 1, new_Ltouch, Rtouch, true)) % mod;
    }

    // one and zero
    if (first_bit && !((Rtouch && Rlimit[k] == 0) || (Ltouch && Llimit[k] == 1))) {
        // if (k == 1 && Llimit == false && Rlimit == true && first_bit == true) cout << Ltouch << ' ' << Rtouch << endl;
        rt = (rt + dp(k - 1, Ltouch, Rtouch, true)) % mod;
    }

    // all zero.
    if (!(Ltouch && Llimit[k] == 1)) {
        bool new_Rtouch = Rtouch;
        if (Rlimit[k] == 1) new_Rtouch = false;
                // if (k == 1 && Llimit == false && Rlimit == true && first_bit == true) cout << new_Ltouch << ' ' << Rtouch << endl;

        rt = (rt + dp(k - 1, Ltouch, new_Rtouch, first_bit)) % mod;
    }
    // cout << k << ' ' << Ltouch << ' ' << Rtouch << ' ' << first_bit << ' ' << rt << endl;
    return rt;
}

long long work(long long L, long long R) {
    for (int i = 62; i >= 0; i--) {
        Llimit[i] = (L >> i) & 1;
        Rlimit[i] = (R >> i) & 1;
    }
    return dp(62, true, true, false);
}

int main() {
    long long L, R;
    cin >> L >> R;
    cout << work(L, R) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define lc nd<<1,l,mid
#define rc nd<<1|1,mid+1,r
#define wk 301010
using namespace std;
int n,m,K,topl,topr,ans,sz;
int ma[wk<<3],lt[wk<<3];
int num[wk<<1];
struct evol{int x,y;}stl[wk],str[wk],a[wk];
bool cmp(evol u,evol v){ return u.y<v.y;}
void build(int nd,int l,int r)
{
	lt[nd]=0;
	if(l==r) return (void)(ma[nd]=n+m-num[l]);
	int mid=(l+r)/2;
	build(lc),build(rc);
	ma[nd]=max(ma[nd<<1],ma[nd<<1|1]);
}
void c_add(int nd,int k){ lt[nd]+=k,ma[nd]+=k;}
void pd(int nd)
{
	c_add(nd<<1,lt[nd]);
	c_add(nd<<1|1,lt[nd]);
	lt[nd]=0;
}
void add(int nd,int l,int r,int ql,int qr,int k)
{
	if(ql>qr) return;
	if(num[l]>=ql&&num[r]<=qr)
	{
		c_add(nd,k);
		return ;
	}
	int mid=(l+r)/2;
	if(lt[nd]) pd(nd);
	if(ql<=num[mid]) add(lc,ql,qr,k);
	if(qr>num[mid]) add(rc,ql,qr,k);
	ma[nd]=max(ma[nd<<1],ma[nd<<1|1]);
}
int query(int nd,int l,int r,int ql,int qr)
{
	if(num[l]>qr||num[r]<ql) return 0;
	if(num[l]>=ql&&num[r]<=qr) return ma[nd];
	int mid=(l+r)/2;
	if(lt[nd]) pd(nd);
	return max(query(lc,ql,qr),query(rc,ql,qr));
}
void addl(evol k)
{
	add(1,1,sz,stl[topl].y,k.y-1,-n/2);
	while(topl&&k.x>stl[topl].x)
	{
		add(1,1,sz,stl[topl-1].y,stl[topl].y-1,stl[topl].x-n/2);
		topl--;
	}
	add(1,1,sz,stl[topl].y,k.y-1,n/2-k.x);
	stl[++topl]=k;
}
void addr(evol k)
{
	add(1,1,sz,str[topr].y,k.y-1,n/2-n);
	while(topr&&k.x<str[topr].x)
	{
		add(1,1,sz,str[topr-1].y,str[topr].y-1,n/2-str[topr].x);
		topr--;
	}
	add(1,1,sz,str[topr].y,k.y-1,k.x-n/2);
	str[++topr]=k;
}
void work()
{
	sort(a+1,a+K+1,cmp);
	build(1,1,sz);
	for(int i=1;i<=K;i++)
	{
		int Ma=query(1,1,sz,0,a[i].y);
		ans=max(ans,(Ma-(m-a[i].y))*2);
		if(a[i].x<=n/2) addl(a[i]);
		else addr(a[i]);
	}
	ans=max(ans,ma[1]*2);
}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=K;i++)
	scanf("%d%d",&a[i].x,&a[i].y),num[i+i-1]=a[i].y,num[i+i]=max(0,a[i].y-1);num[K+K+1]=0;
	sort(num+1,num+K+K+2);
	sz=unique(num+1,num+K+K+2)-num-1;
	stl[0].y=str[0].y=0;
	work();
	swap(n,m);
	for(int i=1;i<=K;i++)
	swap(a[i].x,a[i].y),num[i+i-1]=a[i].y,num[i+i]=max(0,a[i].y-1);num[K+K+1]=0;
	sort(num+1,num+K+K+2);
	sz=unique(num+1,num+K+K+2)-num-1;
	stl[0].y=str[0].y=topl=topr=0;
	work();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 27264
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,w,l,d,flag=0;
    string s;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            if (flag!=0) {
                cout<<endl;
            }
            std::multimap<int,string,greater<int>> map;
            int score=0;
            for (int i=0;i<n;i++) {
                cin>>s>>w>>l>>d;
                score=w*3+d;
                map.insert(make_pair(score,s));
            }
            for (auto const& entry: map) {
                cout<<entry.second<<","<<entry.first<<endl;
            }
            flag=1;
        }
    }
    
}



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

typedef long long int ll;
using ii= pair<ll,ll>;
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll n;
    cin>>n;

    string s;
    cin>>s;
   
    ll count=0;

   
   

 
    ll i=0;
    ll j=n-1;

   

    while(i<j&&i<n&&j>=0){
    	
    	while(s[i]=='R'&&i<n){
    		i++;
    	}
    	while(s[j]=='W'&&j>0){
    		j--;
    	}


        if(s[i]=='W'&&s[j]=='R'&&i<n&&j>=0&&i<j){
        	s[i]='R';
    	    s[j]='W';
    	    count++;
    	    i++;
    	    j--;
        }
    	
    }


    if(count==0) cout<<0<<"\n";
    else{
    	for(ll j=0;j<n-1;j++){
    	    if(s[j]=='W'&&s[j+1]=='R'){
    	    	s[j]='R';
    	    	count++;
    	    }
        }
        cout<<count<<"\n";
    } 
    	
  
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[0] + a[1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define nmax 200010
#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007

#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;
using namespace std::chrono;

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

int n, s;
int a[3010], dp[3010][3010][3];

int f(int x)
{
    if (x >= MOD1) return x - MOD1; else
        return x;
}

int main()
{
    scanf("%d %d", &n, &s);

    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    dp[0][0][0] = 1;

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= s; j++) {

            dp[i + 1][j][0] = f(dp[i + 1][j][0] + dp[i][j][0]);
            dp[i + 1][j][1] = f(dp[i + 1][j][1] + f(dp[i][j][0] + dp[i][j][1]));
            dp[i + 1][j][2] = f(dp[i + 1][j][2] + f(f(dp[i][j][0] + dp[i][j][1]) + dp[i][j][2]));

            if (j + a[i + 1] <= s) {

                dp[i + 1][j + a[i + 1]][1] = f(dp[i + 1][j + a[i + 1]][1] + f(dp[i][j][0] + dp[i][j][1]));
                dp[i + 1][j + a[i + 1]][2] = f(dp[i + 1][j + a[i + 1]][2] + f(dp[i][j][0] + dp[i][j][1]));
            }
        }

    printf("%d", dp[n][s][2]);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 106240
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b,c,d;
 	bool ans=false;
 	cin >> a>>b>>c>>d;
 	if(abs(a-c)<=d){
 		ans=true;
 	}else if(abs(a-b)<=d&&abs(b-c)<=d){
 		ans=true;
 	}
 	if(ans){
 		cout << "Yes" << endl;
 	}else{
 		cout << "No" << endl;
 	}
 }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        char[] chars = str.toCharArray();
        int cnt = 0;
        for(int i = 0; i < chars.length/2; i++){
            if( chars[i] == chars[chars.length-1-i] ){
                continue;
            } else {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 22996
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    h0=h[i]
    h1=h[i-1]
    h2=h[i-2]
    dp[i]=min(abs(h1-h0)+dp[i-1],abs(h2-h0)+dp[i-2])
print(dp[-1])

Measured memory_bytes: 13980
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
   
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
   

    public static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        var input = Reads();
        var n = input[0];
        var m = input[1];
        var s = new long[m];
        var c = new long[m];
        var d = new Dictionary<long, long>();
        bool f = false;
         for(int i = 0; i < m; i++)
        {
            input = Reads();
            if ((n == 2||n==3) && input[0] == 1 && input[1] == 0)
                f = true;
            else if (!d.ContainsKey(input[0]))
                d.Add(input[0], input[1]);
            else
            {
                if (d[input[0]] != input[1])
                    f = true;               
            }
        }
        long answer = 0;
        foreach(KeyValuePair<long,long> item in d)
        {
            answer += item.Value * (long)Math.Pow(10, n - item.Key);
        }
        if (f)
            Console.WriteLine(-1);
        else
        {
            if (n == 1)
                Console.WriteLine(answer);
            if (n == 2)
            {
                if (answer < 10)
                    Console.WriteLine(answer + 10);
                else
                    Console.WriteLine(answer);
            }
            if (n == 3)
            {
                if (answer < 100)
                    Console.WriteLine(answer + 100);
                else
                    Console.WriteLine(answer);
            }
        }     
       
        Console.Out.Flush();

    }
}

Measured memory_bytes: 13280
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  long N;
  cin >> N;
  string s;
  cin >> s;
  int i = 0, j = N - 1, count = 0;
  while (true) {
    while (s[i] != 'W' && i < N) i++;
    while (s[j] != 'R' && j >= 0) j--;
    if (i >= j) break;
    s[i] = 'R';
    s[j] = 'W';
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3712
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, Y = mi()
    for x in range(N+1):
        for y in range(N+1):
            z = N-x-y
            if 0 <= z <= N and (10000*x+5000*y+1000*z==Y):
                print(x, y, z)
                return
    print(-1, -1, -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67460
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char arr[19];
	cin>>arr;
	for(int i=0;i<19;i++)
	{
		if(arr[i]==',')
		{
			arr[i]=' ';
		}
	}
	cout<<arr;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val in = (1 to 3).map(_ => sc.nextLong).sorted

  if (in.exists(_ % 2 == 0)) {
    println(0)
  } else {
    println(in(0) * in(1))
  }
}


Measured memory_bytes: 25664