akhauriyash/Code-Regression huggingface dataset:
tex = input()
num = [int(i) for i in tex]

n = 3
pos = []

for i in range(2 ** n):
    tes = num[0]
    shiki = ""
    sep = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            sep[j] = 1
    for ind, su in enumerate(num):
        shiki += str(num[ind])
        if ind < len(sep):
            if sep[ind] == 1:
                tes += num[ind + 1]
                shiki += "+"
            if sep[ind] == 0:
                tes -= num[ind + 1]
                shiki += "-"
    shiki += "=7"
    if tes == 7:
        print(shiki)
        break

Measured memory_bytes: 38256
#include<iostream>
#include <climits>
#include <cstdint>
#include<cmath>

//#define int long long

using namespace std;

int calcMinCost(int dp[],int n,int k){
    int arr[n];
    arr[0] = 0;
    for(int i = 1;i<n;i++){
        int curr = INT_MAX;
        arr[i] = curr;
        for(int j = i-1;j>=0 and (i-j) <= k;j--){
            arr[i] = min(arr[i],abs(dp[i]-dp[j] )+ arr[j]);
        }
    }
    return arr[n-1];
}

int main(int argc, char const *argv[]) {
  /* code */
  int n,k;
  cin >> n >> k;
  int dp[n];
  for(int i = 0;i < n;i++){
    cin >> dp[i];
  }
  cout<<calcMinCost(dp,n,k)<<endl;
  return 0;
}


Measured memory_bytes: 1024
N, x = map(int, input().split())
A = list(map(int, input().split()))

cnt = 0
for i, a in enumerate(sorted(A)):
    if a <= x:
        if i == N - 1 and a < x:
            break
        else:
            cnt += 1
            x -= a
    else:
        break

print(cnt)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)

typedef pair<ll,ll> pp;
int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll f(char x, ll r, ll s, ll p){
    if(x == 's') return r;
    else if(x == 'r') return p;
    else return s;
}

void solve(){
    ll n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    char dp[n];
    for(ll i = 0;i < n;i++){
        if(i-k >= 0){
            if(t[i] == t[i-k]){
                if(dp[i-k] == 'w') dp[i] = 'd';
                else dp[i] = 'w';
            }
            else{
                dp[i] = 'w';
            }
        }
        else{
            dp[i] = 'w';
        }
    }
    ll count = 0;
    for(ll i=0;i < n;i++){//cout << dp[i] << " ";
        if(dp[i] == 'w') count += f(t[i], r, s, p);
    }//cout << endl;
    cout << count << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll t; cin >> t; while(t--)
        solve();
}


Measured memory_bytes: 592
#include <stdio.h>
#define M 50
int X[M];long long Z[M+1][M*M+1];
int main(){
	int N,A,S=0;
	long long R=0;
	scanf("%d%d",&N,&A);
	for(int i=0;i<N;i++)scanf("%d",X+i);
	Z[0][0]=1;
	for(int i=0;i<N;i++){
		S+=X[i];
		for(int k=i;k>=0;k--)for(int j=S;j>=X[i];j--)Z[k+1][j]+=Z[k][j-X[i]];
	}
	for(int i=1;i<=N;i++)R+=Z[i][i*A];
	printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 1152
from collections import deque
k = int(input())
if k <= 9: print(k)
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
count = 9
while count <= k:
    X = que.popleft()
    if X%10==0: check=[0, 1]
    elif X%10==9: check=[8, 9]
    else: check = [X%10-1, X%10, X%10+1]
    for i in check:
        que.append(X*10+i)
        count += 1
        if count == k:
            print(que[-1])
            exit()

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define MAX_N 200000
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, a[MAX_N+5], b[MAX_N+5];
int into[MAX_N+5], outo[MAX_N+5];
int s, t, f[MAX_N+5], pre[MAX_N+5];
queue <int> que; bool mrk[MAX_N+5];
vector <int> G[MAX_N+5], R[MAX_N+5];
bool chk() {
	for (int u = s, v = pre[u]; ; u = v, v = pre[u])
		{if (f[u] == f[v]) return false; if (u == t) break;}
	return true;
}
int main() {
	read(n);
	for (int i = 1, fa; i <= n; i++)
		read(fa), 
		G[fa].push_back(i), outo[fa]++, 
		R[i].push_back(fa), into[i]++;
	for (int i = 1; i <= n; i++)
		if (!outo[i]) que.push(i);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		memset(mrk, false, sizeof mrk);
		for (int v : G[u]) mrk[f[v]] = true;
		while (mrk[f[u]]) f[u]++;
		for (int v : R[u]) if (!--outo[v]) que.push(v);
	}
	for (int u = 1; u <= n; u++) if (outo[u]) {
		memset(mrk, false, sizeof mrk), s = u;
		for (int v : G[u]) if (!outo[v]) mrk[f[v]] = true; else pre[v] = u;
		while (mrk[a[u]]) a[u]++; b[u] = a[u]+1; while (mrk[b[u]]) b[u]++;
	}
	f[s] = a[s];
	for (int u = s, v = pre[u]; ; u = v, v = pre[u])
		{if (v == s) {t = u; break;} f[v] = f[u] == a[v] ? b[v] : a[v];}
	if (f[t] != a[s] && chk()) return puts("POSSIBLE"), 0;
	f[s] = b[s], t = 0;
	for (int u = s, v = pre[u]; ; u = v, v = pre[u])
		{if (v == s) {t = u; break;} f[v] = f[u] == a[v] ? b[v] : a[v];}
	if (f[t] == a[s] && chk()) return puts("POSSIBLE"), 0;
	return puts("IMPOSSIBLE"), 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   ll n,m; scanf("%lld%lld",&n,&m);
   vector<ll> a(n); rep(i,0,n)scanf("%lld",&a[i]),a[i]/=2;
   ll g=1;
   rep(i,0,n){
      ll d=__gcd(g,a[i]);
      g*=a[i]/d; if(g>inf){printf("0\n"); return 0;}
   }
   rep(i,0,n)if((g/a[i])%2==0){printf("0\n"); return 0;}
   m/=g; m=(m+1)/2;
   printf("%lld\n",m);
   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	vector<int> A(N);
	int ans = 1;
	int even = 1;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		ans *= 3;
		if (A[i] % 2 == 0)
		{
			even *= 2;
		}
	}
	cout << ans - even << endl;
}

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

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
typedef long long int lli;
typedef unsigned long long int uli;
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int m,d,sum=0;
  cin>>m>>d;
  reep(j,1,m){
    reep(i,1,d){
      if(i%10>=2&&i/10>=2&&(i%10)*(i/10)==j){
        ++sum;
       // ou(j<<' '<<i);
      }
    }
  }
  ou(sum);
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    string s;cin>>s;
    char f=s[0];
    int cnt=0,ans=0;
    rep(i,4){
        if(s[i]==f)cnt++;
        else{
            ans=max(ans,cnt);
            f=s[i];
            cnt=1;
        }
    }
    ans=max(ans,cnt);
    if(ans>=3){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3556
#include<iostream>
#include<cmath>

using namespace std;


int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int x[N], y[N], a[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> a[i];
    }

    int left=0, top=H, right=W, bottom=0;
    for(int i=0; i<N; i++){
        switch(a[i]){
            case 1:
                if(x[i] > left){
                    left = x[i];
                }
                break;
            case 2:
                if(x[i] < right){
                    right = x[i];
                }
                break;
            case 3:
                if(y[i] > bottom){
                    bottom = y[i];
                }
                break;
            case 4:
                if(y[i] < top){
                    top = y[i];
                }
                break;
        }
    }
    int width = max(right - left, 0);
    int height = max(top - bottom, 0);
    cout << width*height << '\n';

}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int n;
int a[100010];
int main()
{

    int n;
    cin >> n;
    REP(i, n)
    cin >> a[i];

    multiset<int> s;
    for (int i = 0; i < n; i++)
    {
        auto k = s.lower_bound(a[i]);
        if (s.begin() !=k){
            k--;
            s.erase(k);
        }
        s.insert(a[i]);
    }
   
    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    s64 k;
    cin >> k;

    int ans = 0;
    queue<s64> q;
    rep (i, 9) q.push(i + 1);
    s64 x;
    while (true)
    {
        x = q.front(); q.pop();
        ++ans;
        if (ans == k) break;
        rep (i, 10)
        {
            if (abs(x % 10 - i) <= 1)
            {
                q.push(x * 10 + i);
            }
        }
    }


    cout << x << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
int main(){
    int a,b;
    std::cin>>a>>b;
    if(a<b) std::cout<<"a < b"<<std::endl;
    if(a==b) std::cout<<"a == b"<<std::endl;
    if(a>b) std::cout<<"a > b"<<std::endl;
    return 0;
}


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

ll dp[110][100100];

int main(){
    int N, W; cin >> N >> W;
    int w[110];
    ll v[110];
    for(int i=0; i<N; i++){
        cin >> w[i+1] >> v[i+1];
    }
    for(int i=1; i<=N; i++){
        for(int j=0; j<=W; j++){
            if(j-w[i]>=0){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    ll ans=0;
    for(int j=0; j<=W; j++){
        ans = max (ans, dp[N][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);

  boost::multi_array<int, 2> mat(boost::extents[N + 1][N + 1]);
  // int mat[501][501] = {};

  FOR(i, M) {
    int L, R;
    scanf("%d%d", &L, &R);
    mat[L][R]++;
  }

  FOR(i, N + 1) {
    FOR1(j, i, N) { mat[i][j + 1] += mat[i][j]; }
  }

  for (int i = N; i > 0; i--) {
    FOR1(j, i, N + 1) { mat[i - 1][j] += mat[i][j]; }
  }

  while (Q--) {
    int p, q;
    scanf("%d%d", &p, &q);
    printf("%d\n", mat[p][q]);
  }

  return 0;
}


Measured memory_bytes: 1920
import java.util.*
import java.io.PrintWriter

val pw = PrintWriter(System.out)
val MOD = 1000000007L
val INF = 2147483647
val LINF = 9223372036854775807L

fun main(args: Array<String>){
    solve()
    pw.flush()    
}

fun solve(){
    readLine()
    val a = nextIntList()
    val b = a.sortedDescending()
    val most = b.first()
    val sum = b.drop(1).sum()
    println(max(0, (most - sum - 1).toLong()))
}


// Print
fun println(v: String){
    pw.println(v)
}
fun print(v: String){
    pw.print(v)
}

// Read
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map{ it.toInt() }
fun nextLongList() = next().split(" ").map{ it.toLong() }
fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
fun nextAryln(n: Int) = Array(n){ next() }
fun nextIntAryln(n: Int) = IntArray(n){ nextInt() }
fun nextLongAryln(n: Int) = LongArray(n){ nextLong() }
fun nextDoubleAryln(n: Int) = DoubleArray(n) { nextDouble() }

// Math
fun abs(n: Long) : Long = Math.abs(n)
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong()
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong()
fun prime(from: Long, to: Long = from) : List<Long>{
    return (from..to).filter{ i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all{ j -> i % j != 0L}
    }
}
fun gcd(a: Long, b: Long) : Long = if(a % b == 0L) b else gcd(b, (a % b))
fun lcm(a: Long, b: Long) : Long = a / gcd(a, b) * b
fun modpow(a: Long, n: Long, p:Long = MOD) : Long {
    var res = 1L
    var ar = a
    var nr = n
    while(nr > 0){
        if((nr and 1) == 1L) res = res * ar % p
        ar = ar * ar % p
        nr = nr shr 1
    }
    return res
}
fun modinv(a: Long, p: Long = MOD) : Long = modpow(a, p - 2, p)
fun ncr(n: Long, r: Long) : Long {
    var a = 1L
    var b = 1L
    for (i in 1..r) {
        a = a * (n + 1 - i) % MOD
        b = b * i % MOD
    }
    return modinv(b, MOD) * a % MOD
}


Measured memory_bytes: 37748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int>> alphabet_pos(30);
    rep(i, S.size())
    {
        alphabet_pos[S[i] - 'a'].insert(i);
    }

    vector<int> ans;
    rep(i, Q)
    {
        int y;
        cin >> y;
        if (y == 1)
        {
            int i;
            char c;
            cin >> i >> c;
            i--;
            alphabet_pos[S[i] - 'a'].erase(i);
            alphabet_pos[c - 'a'].insert(i);
            S[i] = c;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int count = 0;
            rep(c, 30)
            {
                auto pos_it = alphabet_pos[c].lower_bound(l);
                if (pos_it == alphabet_pos[c].end())
                    continue;

                if (*pos_it <= r)
                    count++;
            }
            ans.push_back(count);
        }
    }
    printVector(ans);
    return 0;
}

Measured memory_bytes: 24452
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    string s,t; cin>>s>>t;
    int N=s.size();
    int M=t.size();
                
    vector<vector<int> > dp(N+1,vector<int>(M+1));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else{
                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }

    string ans="";
    int i=N;
    int j=M;
    while(i>0 and j>0){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else{
            ans=s[i-1]+ans;
            i--; j--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 70784
<?php

fscanf(STDIN, "%d %d", $a_val, $b_val);

if ( ( ($a_val + $b_val) % 3) === 0 ) {
    echo "Possible" ;
} else if ( ( ($a_val) % 3) === 0 ) {
    echo "Possible" ;
} else if ( ( ($b_val) % 3) === 0 ) {
    echo "Possible" ;
} else {
    echo "Impossible" ;
}
?>

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

int main(){
	string s;
  	cin >> s;
  
  	if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

Measured memory_bytes: 3536
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        boolean jdg = true;;
        for(int i = 0;i < S.length();i++){
            if(i % 2 == 0){
                if(S.charAt(i) == 'L'){
                    jdg = false;
                    break;
                }
            }else{
                if(S.charAt(i) == 'R'){
                    jdg = false;
                    break;
                }
            }
        }
        System.out.println(jdg == true?"Yes":"No");
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int n;
int x[51];
int a;
ll f[51][5001];
const int zero=2500;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(a);
    FOR(i, 1, n){
        read(x[i]);
        x[i]-=a;
    }
    f[0][zero]=1;
    FOR(i, 1, n){
        FOR(j, 0, zero*2) if(f[i-1][j]){
            f[i][j]+=f[i-1][j];
            f[i][j+x[i]]+=f[i-1][j];
        }
    }
    write(f[n][zero]-1);
}

Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rndf(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define rnddiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) * 2 >= (ll)(b) ? 1 : 0))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

class Binary_Indexed_Tree {
private:
	vll bits;
	int n;
public:
	Binary_Indexed_Tree(vll a) {
		n = (int)pow(2, ceil(log2(a.size())));
		bits = vll(n, 0);
		Loop(i, a.size()) update(i, a[i]);
	}
	void update(int k, ll x) {
		for (int index = k; index < n; index |= index + 1) {
			bits[index] += x;
		}
	}
	// note: sum of [s, t)
	ll sum(int s, int t) {
		ll ret = 0;
		for (int index = t - 1; index >= 0; index = (index & (index + 1)) - 1) {
			ret += bits[index];
		}
		for (int index = s - 1; index >= 0; index = (index & (index + 1)) - 1) {
			ret -= bits[index];
		}
		return ret;
	}
};

int main() {
	int n, k; cin >> n >> k;
	Binary_Indexed_Tree bit(vll(n, 0));
	Loop(i, k) {
		int c, x, y; cin >> c >> x >> y;
		if (c == 0) bit.update(x - 1, y);
		else cout << bit.sum(x - 1, y) << endl;
	}
}


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

int main()
{
  int d,n;
  cin >> d >> n;
 
  if(n == 100){
    n = 101;
  }
  if(d == 0){
    cout << n << endl;
    return 0;
  }else if(d == 1){
    cout << n * 100 << endl;
  }else if(d == 2){
    cout << n * 100 * 100 << endl;
  }
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <typeinfo>
using namespace std;
typedef long long ll;

string a, b, c;

int main()
{
  cin >> a >> b >> c;
  if (*(a.end() - 1) == *b.begin() && *(b.end() - 1) == *c.begin()){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int[] a=ir.nextIntArray(n);
		HashSet<Integer> st=new HashSet<>();
		for(int i=0;i<n;i++)
			st.add(a[i]);
		out.println(st.size());
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 21204
Module Module1

    Sub main()
        Dim userInput As String
        Dim result As String

        Const OSATSU As Integer = 1000


        ' データの入力
        userInput = Console.ReadLine()
        result = OSATSU - (CInt(userInput) Mod OSATSU)
        result = result Mod OSATSU

        ' 処理結果を返す
        Console.WriteLine(result)
    End Sub
End Module

Measured memory_bytes: 28384
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
typedef struct {
	ll point;
	ll node;
} Pair;

typedef struct {
	int to, from;
	ll cost;
} Edge;

int parent[100005];

int root(int a);
void unite(int a, int b);
int Pair_cmp(const Pair *, const Pair *);
int Edge_cmp(const Edge *, const Edge *);

ll n;
Pair x[100005];
Pair y[100005];
Edge e[2 * 100005];

int main()
{
	for (ll i = 0; i < sizeof(parent) / sizeof(parent[0]); i++) {
		parent[i] = -1;
	}

	int e_num = 0;
	ll ans = 0;

	scanf("%lld", &n);
	for (ll i = 0; i < n; i++) {
		scanf("%lld %lld", &x[i].point, &y[i].point);

		x[i].node = y[i].node = i + 1;
	}

	qsort(x, n, sizeof(Pair), (int (*)(const void *, const void *))Pair_cmp);
	qsort(y, n, sizeof(Pair), (int (*)(const void *, const void *))Pair_cmp);

	for (ll i = 0; i < n - 1; i++) {
		e[e_num].to = x[i].node;
		e[e_num].from = x[i + 1].node;
		e[e_num].cost = x[i + 1].point - x[i].point;

		e_num++;

		e[e_num].to = y[i].node;
		e[e_num].from = y[i + 1].node;
		e[e_num].cost = y[i + 1].point - y[i].point;

		e_num++;
	}

	qsort(e, e_num, sizeof(Edge), (int (*)(const void *, const void *))Edge_cmp);

	for (ll i = 0; i < e_num; i++) {

		if (root(e[i].to) != root(e[i].from)) {
			unite(e[i].to, e[i].from);
			ans = ans + e[i].cost;
		}

	}

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

}

int root(int a)
{
	if (parent[a] < 0) {
		return a;
	} else {
		return parent[a] = root(parent[a]);
	}
}

void unite(int a, int b)
{
	a = root(a);
	b = root(b);

	if (a != b) {
		parent[a] += parent[b];
		parent[b] = a;
	}

	return;
}

int Pair_cmp(const Pair *x, const Pair *y)
{
	if (x->point > y->point) {
		return 1;
	} else if (x->point == y->point) {
		return 0;
	} else {
		return -1;
	}
}

int Edge_cmp(const Edge *x, const Edge *y)
{
	if (x->cost > y->cost) {
		return 1;
	} else if(x->cost == y->cost) {
		return 0;
	} else {
		return -1;
	}
}


Measured memory_bytes: 11488
import heapq
N, M = map(int, input().split())
As = list(map(int, input().split()))
q = []
for A in As:
  heapq.heappush(q, -A)
for i in range(M):
  X = -heapq.heappop(q)
  X2 = X//2
  heapq.heappush(q, -X2)
r = -sum(q)
print(r)


Measured memory_bytes: 14180
N, K = map(int, input().split())
P = list(map(int, input().split()))

P = [(1+p)/2 for p in P]

tmp = sum(P[:K])
maxV = tmp

for i in range(N-K):
  tmp += P[i+K] - P[i]
  maxV = max(maxV, tmp)
print(maxV)

Measured memory_bytes: 25060
#include <algorithm>
//#include <cstdio>
//#include <functional>
//#include <bits/stdc++.h>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
 
int main()
{
	int a,b,c; 
	int ans=0; 
	
	cin>>a>>b>>c;

	int t;
	if(a<b) {
		t=a; a=b;b=t;
	}
	if(a<c) {
		t=a; a=c;c=b;b=t;
	} else {
		t=b; b=max(t,c); c=min(t,c);
	}
	
	ans=a-b;
	ans+=(b-c)/2;
	if((b-c)%2) ans+=2;
	
	cout<<ans;
    rt0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
vector<bool> seen;
vector<int> U, V;
void dfs(Graph &G, int v, int num){
  seen[v]=true;
  U[v]=num;
  num++;  
  for(int next_v: G[v]){
    if(seen[next_v]) continue;
    dfs(G, next_v, num);
  }
}
int main(){
  int N, u, v;
  cin >> N >> u >> v;
  Graph G(N+1);
  U.assign(N+1,0);
  V.assign(N+1,0);
  for(int i=1; i<=N; i++){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);    
  }
  int ans=0;
  seen.assign(N+1, false);
  int num=0;
  dfs(G, v, num);
  num=0, V=U;
  seen.assign(N+1, false);
  dfs(G, u, num);
  for(int i=1; i<=N; i++){
    if(V[i]>U[i]){
      ans=max(ans,V[i]);
    }
  }
  ans--;
  cout << ans << endl;
}


Measured memory_bytes: 10368
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int times = Integer.parseInt(br.readLine());
            if (times == 0) { break; }
            
            Map<String, Long> data = new LinkedHashMap<>();
            for (int i=1; i <= times; i++) {
                String[] e = br.readLine().split(" ");
                data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]), Long::sum);
            }
            
            int count = 0;
            for(Map.Entry<String, Long> e : data.entrySet()){
                if(e.getValue() >= 1_000_000){
                    System.out.println(e.getKey());
                    count++;
                }
            }
            if (count == 0) { System.out.println("NA"); }
        }
    }
}

Measured memory_bytes: 31512
n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
    r = i -a[i]
    ans += dic.get(r, 0)
    l = a[i] + i
    dic[l] = dic.get(l, 0) + 1
print(ans)

Measured memory_bytes: 118740
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    std::cout << ((c - (a-b) > 0) ? c - (a-b) : 0) << std::endl;
    return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> l(n + 1, 0), r(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'W')
        {
            l[i + 1] = l[i] + 1;
            r[i + 1] = r[i];
        }
        else
        {
            r[i + 1] = r[i] + 1;
            l[i + 1] = l[i];
        }
    }

    int ans = 1001001001;
    for (int i = 1; i < n + 1; i++)
    {
        ans = min(ans, l[i - 1] + r[n] - r[i]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	h, n := readI(), readI()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readI()
	}

	if sum(a) >= h {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func sum(a []int) int {
	b := 0
	for _, v := range a {
		b += v
	}
	return b
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int) 1e9 : (int) 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
    if (a > b) a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
    if (a < b) a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
template <class T, class S> void join(T &a, S terminator) {
    for (auto itr = begin(a); itr != end(a); itr++) {
        if (itr != begin(a)) cout << terminator;
        cout << *itr;
    }
    cout << endl;
}
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
auto out(int a, int b) {
    (a > b ? a += 1 : b += 1);
    cout << a << " " << b << endl;
}
main() {
    int n, m;
    while (cin >> n, n) {
        vector<double> v(n);
        erep(e, v) cin >> e;
        sort(all(v));
        double avg = accumulate(all(v), 0.0) / n;
        auto itr   = upper_bound(all(v), avg);
        cout << (itr == v.end() ? n : itr - v.begin()) << endl;
    }
}


Measured memory_bytes: 3352
n = int(input())
A = list(map(int,input().split()))
cnt = 0
for a in A:
    if a < 0:
        cnt += 1
res = 0
if cnt%2 == 0:
    A = [abs(a) for a in A]
    for a in A:
        res += a
else:
    g = abs(A[0])
    for a in A:
        if abs(a) <= g:
            g = abs(a)
        res += abs(a)
    res -= 2*g
print(res)



Measured memory_bytes: 14412
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll w,h,n;
  cin >> w >> h >> n;
  bool is_white[h][w];
  fill(is_white[0],is_white[h],true);
  REP(i,n){
    ll x,y,a;
    cin >> x >> y >> a;
    REP(j,h){
      REP(k,w){
        if(a==1&&k<x) is_white[j][k]=false;
        if(a==2&&k>=x) is_white[j][k]=false;
        if(a==3&&j<y) is_white[j][k]=false;
        if(a==4&&j>=y) is_white[j][k]=false;
      }
    }
  }
  ll cnt = 0;
  REP(i,h){
    REP(j,w){
      if(is_white[i][j]) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){

  ll N, tmp;
  vector<ll> A;
  cin >> N;
  for(ll i = 0; i < N; i++){
    cin >> tmp;
    A.push_back(tmp);
  }

  // if N is even
  if(N%2 == 0){
    cerr << "N is even." << endl;
    vector<ll> accum(N);
    accum[0] = A[0];
    for(ll i = 2; i < N; i+=2){
      accum[i] = accum[i-2] + A[i];
    }
    accum[N-1] = A[N-1];
    for(ll i = N-3; i >= 1; i-=2){
      accum[i] = accum[i+2] + A[i];
    }
    ll ans = max(accum[N-2], accum[1]);
    for(ll i = 0; i<=N-4; i+=2){
      ans = max(ans, accum[i]+accum[i+3]);
    }

    cerr << "Answer:" << endl;
    cout << ans << endl;

    return 0;
  }
  // N is odd
  else{
    cerr << "N is odd." << endl;
    vector<ll> accum(N);
    accum[0] = A[0];
    for(ll i = 2; i < N; i++){
      accum[i] = accum[i-2] + A[i];
    }
    accum[N-2] = A[N-2];
    for(ll i = N-4; i >= 1; i-=2){
      accum[i] = accum[i+2] + A[i];
    }
    vector<ll> diff(N);
    for(ll i = 1; i <= N-4; i+=2){
      diff[i] = accum[i-1] + accum[i+2] - accum[1];
    }
    for(ll i = 2; i <= N-3; i+=2){
      diff[i] = accum[N-1]-accum[i] + accum[1] - accum[i+1] - accum[1];
    }
    diff[N-2] = accum[N-3] - accum[1];
    diff[0] = accum[2] - accum[1];

    vector<ll> eomax(N);
    eomax[N-3] = diff[N-3];
    for(ll i = N-5; i >= 0; i-=2){
      eomax[i] = max(eomax[i+2], diff[i]);
    }

    ll ans = max(max(accum[N-1]-accum[0], accum[N-3]), accum[1]);
    for(ll oe = 1; oe < N-2; oe+=2){
        ans = max(ans, accum[1]+diff[oe]+eomax[oe+1]);
    }

    cerr << "Answer:" << endl;
    cout << ans << endl;

    return 0;
  }


  
}


Measured memory_bytes: 9576
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int N;
	cin >> N;

	vector<tuple<string, int, int> > guidebook(N);
	rep(i, N) {
		string S;
		int P;
		cin >> S >> P;
		guidebook[i] = make_tuple(S, 100 - P, i + 1);
	}
	sort(ALL(guidebook));

	for (auto restaurant_guide:guidebook) {
		cout << get<2>(restaurant_guide) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c,k;
  cin >>a>>b>>c>>k;
  
  
  
  if(k<a){
  cout <<k<<endl;}
  else if(a<=k&&a+b>=k){
  cout <<a<<endl;}
  else{
    cout<<a-(k-a-b)<<endl;
  }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
main() {
	string a,b;
    cin>>a>>b;
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	sort(a.begin(),a.end());
	if(b>a) puts("Yes");
	else puts("No");
	return 0;
}
//1478932871

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] xs = new int[3];
			int[] ys = new int[3];
			for (int i = 0; i < 3; i++) {
				int a = scanner.next().charAt(0) - 'A';
				xs[i] = a % 3;
				ys[i] = a / 3;
			}
			double[][][] dp = new double[2][3][3];
			int u = 0;
			dp[u][xs[0]][ys[0]] = 1;
			for (int i = 0; i < n; i++) {
				for (int x = 0; x < 3; x++) {
					for (int y = 0; y < 3; y++) {
						for (int[] m : move) {
							int nx = x + m[0];
							int ny = y + m[1];
							if (nx == xs[2] && ny == ys[2] || nx < 0 || 2 < nx
									|| ny < 0 || 2 < ny)
								dp[1 - u][x][y] += dp[u][x][y] / 4;
							else
								dp[1 - u][nx][ny] += dp[u][x][y] / 4;
						}
						dp[u][x][y] = 0;
					}
				}
				u = 1 - u;
			}
			System.out.printf("%.8f\n", dp[u][xs[1]][ys[1]]);
		}
	}

	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

}

Measured memory_bytes: 20592
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    int n;
    while(cin>>n){
        int dp[n+1];
        dp[0] = 1;
        dp[1] = 1;
        REP(i,2,n){
            dp[i] = dp[i-1]+dp[i-2];
        }
        cout<<dp[n]<<endl;
    }
}




Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X,A,B;
  cin>>X>>A>>B;
  int temp = (X-A);
  if(temp==B){
    cout << '0';
  }
  if(B <temp){
    int k = temp/B;
    int p = k*B;
    cout<<(temp-p);
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int n,s,X,x[200000],g;
vector <int> sel;
int gcd (int a, int b){
    if(a<b)swap(a,b);
    while(a%b > 0){
        int c = a%b;
        a = b;
        b = c;
    }
    return b;
}
int main(){
    cin>>n>>X;
    for(int i=1;i<=n;i++){
        cin>>x[i];
    }
    x[n+1]=X;
    n++;
    sort(x+1,x+n+1);
    for(int i=2;i<=n;i++){
        sel.pb (x[i]-x[i-1]);
    }
    int g=sel[0];
    for(int i=1;i<sel.size();i++){
        g = gcd(g,sel[i]);
    }
    cout<<g<<endl;





}


Measured memory_bytes: 1276
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);


//入力変数
int a=sc.nextInt();
int b=sc.nextInt();

//入力値変換


//出力変数
String ans;

//計算
if(a%2==1&&b%2==1){
    ans="Odd";
}else{
    ans="Even";
}

//出力
System.out.println(ans);

}}

Measured memory_bytes: 22484
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		int ac=0,wa=0,tle=0,re=0;

		for(int i=0;i<n;i++) {
			s[i] = sc.next();
		}
		for(int i=0;i<n;i++) {
			if(s[i].equals("AC")) {
				ac++;
			}
			if(s[i].equals("WA")) {
				wa++;
			}
			if(s[i].equals("TLE")) {
				tle++;
			}
			if(s[i].equals("RE")) {
				re++;
			}
		}
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
	}
}

Measured memory_bytes: 63676