akhauriyash/Code-Regression huggingface dataset:
N = input()
A = map(int, raw_input().split())
print ' '.join(map(str, A))

for i in xrange(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
	A[j+1] = A[j]
	j -= 1
    A[j+1] = v
    print ' '.join(map(str, A))


Measured memory_bytes: 4648
#include <iostream>
#include <vector>

class DisjointSet {
private:
	std::vector<int> p, rank;

	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;

			if (rank[x] == rank[y])
				rank[y]++;
		}
	}
public:
	DisjointSet() {};

	DisjointSet(int n) {
		p.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; i++) {
			make_set(i);
		}
	}

	void make_set(int x) {
		p[x] = x;
		rank[x] = 0;
	}

	int find_set(int x) {
		if (p[x] != x) {
			p[x] = find_set(p[x]);
		}
		return p[x];
	}

	void unite(int x, int y) {
		link(find_set(x), find_set(y));
	}

	bool same(int x, int y) {
		return find_set(x) == find_set(y);
	}
};


int main()
{
	using namespace std;

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

	DisjointSet ds = DisjointSet(N + M + 10);

	for (int i = 1; i <= N; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int lang; cin >> lang;
			ds.unite(i, N + lang);
		}
	}

	for (int i = 1; i <= N; i++) {
		if (!ds.same(1, i)) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
        lint h,w,d;
        cin>>h>>w>>d;
        map<lint,P>mp;
        rep(i,h){
            rep(j,w){
                lint a;
                cin>>a;
                mp[a]=make_pair(i,j);
            }
        }
        vector<vector<lint>> x(d);
        rep(i,d){
            x[i].push_back(0);
            rep(j,h*w){
                lint y=i+1+(j+1)*d;
                if(y>h*w)break;
                lint s,v,s1,v1;
                tie(s,v)=mp[y-d];
                tie(s1,v1)=mp[y];
                lint h=abs(s1-s)+abs(v1-v);
                x[i].push_back(h+x[i][j]);
            }

        }
        lint q;
        cin>>q;
        rep(i,q){
            lint a,b;
            cin>>a>>b;
            lint c=a%d-1;
            if(c==-1)c=d-1;
            cout<<x[c][(b-c-1)/d]-x[c][(a-c-1)/d]<<endl;
        }
      }
  
     


Measured memory_bytes: 11008
#include <iostream>
#include <iomanip>
#define nmax 100005
using namespace std;
    int dp[nmax],p[nmax];
int modul (int x)
{
    if (x<0)
    {
        return -x;
    }
    return x;
}
int cost (int k,int i)
{
    return dp[k]+modul(p[k]-p[i]);
}
int main()
{
int i,j,n,k;

cin>>n>>k;
for (i=1;i<=n;i++)
    cin>>p[i];
    dp[2]=modul(p[1]-p[2]);
for (i=3;i<=n;i++)
{
    dp[i]=1000000000;
    for (j=max(1,i-k);j<=i;j++)
    dp[i]=min(dp[i],cost (j,i));
}
cout<<dp[n];
    }


Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

N = int(readline())
A = [None] * N
for i in range(N):
  # 後ろからpopできるように逆順リストで持つ
  A[i] = list(map(lambda x:x - 1,map(int,readline().split())))[::-1]
  
# 今日試合ができる可能性がある人リスト
candi = set(range(N))

day = 0
while candi:
  day += 1
  nex = set()
  done = set()
  for player in candi:
    if player in done:
      continue
    # player が試合できるかチェック
    if len(A[player]) == 0:
      continue
    rival = A[player][-1]
    if rival in done:
      continue
    if A[rival][-1] == player:
      # 試合できる
      A[player].pop()
      A[rival].pop()
      if A[player]:
        nex.add(player)
      done.add(player)
      if A[rival]:
        nex.add(rival)
      done.add(rival)
  if len(done) == 0:
    # 一試合もできなかった
    print(-1)
    exit(0)
  candi = nex
  
print(day)

Measured memory_bytes: 91756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll maxh = 5e4 + 10;
const ll maxn = 1010;
ll p[maxn], c[maxn];
ll dp[maxh];

int main()
{
    ll n, h;
    scanf("%lld%lld", &h, &n);
    for(ll i = 0; i < n; i++) scanf("%lld%lld", &p[i], &c[i]);
    fill(dp, dp +  maxh, INF);
    dp[0] = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= h; j++) {
            dp[j + p[i]] = min(dp[j + p[i]], dp[j] + c[i]);
        }
    }
    ll mins = INF;
    for (ll i = h; i < maxh; i++) mins = min(mins, dp[i]);
    printf("%lld\n", mins);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int A[100009], B[100009];

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

	int N; cin >> N;
	for (int i = 0; i <= N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	ll ans = 0;

	for (int i = 0; i < N; i++) {
		if (A[i] >= B[i]) {
			// できるだけ倒す
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}
		else {
			// 全部倒す
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;

			// 次の街もできるだけ倒す
			if (A[i + 1] >= B[i]) {
				ans += B[i];
				A[i + 1] -= B[i];
				B[i] = 0;
			}
			else { // 全部倒せた
				ans += A[i + 1];
				B[i] -= A[i + 1];
				A[i + 1] = 0;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		sc.close();
		int cnt=0;
		for(i=0;i<n;i++) {
			if(a[i]==b[i]) {
				if(b[i]!=c[i]) {
					cnt++;
				}
			} else {
				if(b[i]==c[i]) {
					cnt++;
				} else if(a[i]==c[i]) {
					cnt++;
				} else {
					cnt+=2;
				}
			}
		}
		out.println(cnt);
	}
}


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

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

int main(){
    int k;
    int n;
    cin>>k>>n;
    int prev=0;
    int now=0;
    int mmax=0;
    int first=0;
    cin>>prev;
    first=prev;
    for(int i=1;i<n;i++){
        cin>>now;
        mmax=max(mmax,now-prev);
        prev=now;
    }
    mmax=max(mmax,first-prev+k);
    cout<<k-mmax<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int main()
{
    char a[55],b[55];
    scanf("%s%s",&a,&b);
    int l1=strlen(a);
    int l2=strlen(b);
    if(l1<l2)
    {
        printf("UNRESTORABLE\n");
        return 0;
    }
    int l=l2-1,j=0,k=0;
    for(int i=l1-1;i>=0;i--)
    {
        
        if(a[i]=='?'||a[i]==b[l])
            l--;
        else
        {
            i+=l2-l-1;
            l=l2-1;
        }
        if(l==-1)
        {
            for(;j<l2;i++,j++)
            {
                a[i]=b[j];
            }
            for(i=0;i<l1;i++)
            {
                if(a[i]=='?') a[i]='a';
                printf("%c",a[i]);
            }
            printf("\n");
            return 0;
        }
    }
    printf("UNRESTORABLE\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;

int main()
{
	int a,b;
	cin >> a >> b;
	if (a < b)
	{
		int temp = a;
		a = b;
		b = temp;
	}
	for (int i = 0;i<a;i++)
	{
		cout << b;
	}
	return 0;
}



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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long a;
  cin >> a;
  double b;
  cin >> b;
  int c = b * 100 + 0.5;
  a *= c;
  a /= 100;
  cout << a << '\n';
}


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

int main(){
    int n,q,i,t,x; cin >> n >> q;
    queue<int>Q[n];
    while(q--){
        cin >> i;
        if(i==0){
            cin >> t >> x;
            Q[t].push(x);
        }
        else if(i==1){
            cin >> t;
            if(Q[t].size()!=0){
                cout << Q[t].front() <<"\n";
            }
        }
        else{
            cin >> t;
            if(Q[t].size()!=0){
                Q[t].pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4392
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	int n;
	set<string> Set;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		Set.insert(s);
	}
	cout << Set.size();
	return 0;
}

Measured memory_bytes: 19232
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# include <string>
# include <set>
# include <map>
# include <bitset>
# include <queue>
# include <iomanip>

# define FILE
using namespace std;

const int N = 1e5 + 100;

int n, cnt[N][30];
long long ans;
string s[N];

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );
    cin>> n;
    for( int i = 1; i <= n; i ++ ){
        cin >> s[i];
        sort( s[i].begin(), s[i].end() );
    }
    sort( s+1, s+n+1 );
    int l = 1, r = 1;
    while( r <= n ){
        if( s[r] != s[l] ){
            l = r;
        }
        ans += r-l;
        r++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 105
#define MAXV 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,cap,costs[MAXN],vals[MAXN];
ll dp[MAXN][MAXV];

int main(){
    scanf("%d %d",&len,&cap);
    for(int i=1; i<=len; i++)
        scanf(" %d %d",&costs[i],&vals[i]);
    for(int i=1; i<=len; i++){
        for(int k=1; k<=cap; k++){
            if(k < costs[i]) dp[i][k] = dp[i-1][k];
            else dp[i][k] = max(dp[i-1][k],dp[i-1][k-costs[i]]+vals[i]);
        }
    }
    printf("%lld\n",dp[len][cap]);
}


Measured memory_bytes: 79360
def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    frac=[1]
    for i in range(1,n+1):
        frac.append(frac[-1]*i%MOD)
    
    fracinv=[inv(frac[i]) for i in range(n+1)]


    dp=[[0]*(n+1) for _ in range(k)]

    for x in range(a[0]+1):
        dp[0][x]=frac[n]*frac[n-x]*fracinv[a[0]-x]%MOD*fracinv[n-a[0]]*fracinv[x]%MOD

    for i in range(k-1):
        ai=a[i+1]
        for j in range(n+1):
            for x in range(ai+1):
                p=j+x
                if p>n: break
                tmp=dp[i][j]*frac[n-x]%MOD*fracinv[ai-x]*fracinv[n-ai]%MOD*fracinv[x]
                dp[i+1][p]=(dp[i+1][p]+tmp)%MOD
    print(dp[k-1][n])

if __name__ == "__main__":
    main()

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

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

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

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

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


Measured memory_bytes: 256
n,m = map(int,input().split())
max_int = 1000000007
a = [-1] * (m+1)
for i in range(m):
    a[i] = int(input())
piv = 0
b = [1] * (n+1)
if a[0] == 1:
    piv += 1
    b[1] = 0
for i in range(2,n+1):
    if i == a[piv]:
        piv += 1
        b[i] = 0
    else:
        b[i] = b[i-1] + b[i-2]
        b[i] %= max_int

print(b[n]%max_int)


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

int main() {
  int n;
  cin >> n;
  
  int a;
  int max = 0;
  long long sum = 0;
  
  for (int i = 0; i < n; i++){
    cin >> a;
    
    if (a >= max){
      max = a;
    }
    else{
      sum += (max - a);
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll arr[maxn], prefix[maxn];
ll check(int val, int n) {
    ll cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int pos = lower_bound(arr + 1, arr + 1 + n, val - arr[i]) - arr;
        cnt += n + 1 - pos;
    }
    return cnt;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; ll m; cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    for (int i = 1; i <= n; ++i) prefix[i] = prefix[i - 1] + arr[i];
    int left = 0, right = 2 * maxn; ll res = 0;
    while (left <= right) {
        ll mid = (left + right) / 2; ll cnt;
        if ((cnt = check(mid, n)) < m)
            right = mid - 1;
        else {
            left = mid + 1, res = 0;
            for (int i = 1; i <= n; ++i) {
                int pos = lower_bound(arr + 1, arr + 1 + n, mid - arr[i]) - arr;
                res += (n + 1 - pos) * arr[i] + prefix[n] - prefix[pos - 1];
            }
            if (cnt > m) res -= (cnt - m) * mid;
        }
    }
    cout << res << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, t;
  	int a, b;
  	int c[5000], d[5000];
    cin >> n >> t;
    for(int i=0;i<n;i++) {
        cin >> a >> b;
        for(int j = t;j--;) {
            c[j] = max(c[j], d[j] + b);
            if(j>=a) {
                c[j] = max(c[j], c[j-a] + b);
              	d[j] = max(d[j], d[j-a] + b);
            }
        }
    }
    cout << c[t-1] << endl;
    return 0;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); 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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll N,K;
    cin >> N >> K;

    ll tmp = (N+K)%K;
    cout << min(abs(tmp-K), (N+K)%K) << endl;
}


Measured memory_bytes: 256
n,c,k = map(int,input().split())
t = []
for i in range(n):
  t.append(int(input()))

t.sort()
ans = 0
now = 0
ter = -1
for i in range(n):
  if ter < t[i]:
    ans += 1
    ter = t[i]+k
    now = 1
  else:
    if(c<=now):
      ans+=1
      ter = t[i]+k
      now = 1
    else:
      now += 1
      
print(ans)

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, k; cin >> n >> k;
    deque<ll> deq;
    REP(i, 0, n){
        ll a; cin >> a;
        deq.pb(a);
    }
    ll ans = 0;
    REP(i, 0, k+1){ //取り出す回数
        REP(l, 0, i+1){
            deque<ll> cdeq = deq;
            vector<ll> lis;
            int j = 0;
            for(; j < l; j++){ //front
                if(cdeq.empty()){
                    continue;
                }
                lis.pb(cdeq.front());
                cdeq.pop_front();
            }
            for(; j < i; j++){ //back
                if(cdeq.empty()){
                    continue;
                }
                lis.pb(cdeq.back());
                cdeq.pop_back();
            }
            sort(ALL(lis));
            ll mid = 0;
            int c = k - lis.size();
            REP(i, 0, lis.size()){
                if(lis[i] < 0 && c > 0){
                    c--;
                    continue;
                }
                mid += lis[i];
            }
            /*if(l == 3){
                cout<< i  << endl;
                REP(i, 0, lis.size()){
                    cout << lis[i] << " ";
                }
                cout << endl;
            }  */
            chmax(ans, mid);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    C *= 2;
    if (A + B > C) {
        if (X < Y) {
            swap(X, Y); swap(A, B);
        }
        ans = Y * C;
        X -= Y;
        ans += min(A, C) * X;
        cout << ans << endl;
        return 0;
    }
    else {
        ans += X * A + Y * B;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#def main(S, b):
if __name__ == '__main__':
    # n, w, k, V = map(int, input().split())

    n = int(input())

    ans = 0
    for i in range(n):
        if ((i + 1) % 5 == 0 or (i + 1) % 3 == 0):
            pass
        else:
            ans += i + 1

    print(ans)


Measured memory_bytes: 9104
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = input.split(/\n/);
let result = 0;
arr.forEach(item => {
  const formula = item.split(" ");
  const a  = Number(formula[0]);
  const op = formula[1];
  const b  = Number(formula[2]);
  if(op == '?') return;
  if(op == '+') result = result + Number(a + b) + '\n';
  if(op == '-') result = result + Number(a - b) + '\n';
  if(op == '*') result = result + Number(a * b) + '\n';
  if(op == '/') result = result + Math.floor(Number(a / b)) + '\n';
})
console.log(result.trim());




Measured memory_bytes: 15440
import itertools
import copy
  
N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q

now = 0
ans = 0

for i in range(Q):
  a[i],b[i],c[i],d[i] = map(int, input().split())
  
def dfs(A):
#  print('input',A)
  global ans
  if (len(A) == N):
    now = 0
    for i in range(Q):
      if A[b[i]-1] - A[a[i]-1] == c[i]:
        now += d[i]
    ans = max(now,ans)
    return
  if len(A) == 0:
    A=[1]
  else:
    A.append(A[-1])

  while A[-1] <= M:
#    print('mid',A,A[-1])
    dfs(copy.deepcopy(A))
    A[-1] +=1
  
  
dfs(list([1]))  
print(ans)

Measured memory_bytes: 84040
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int x; rd(x);

  auto ushi="ai1333".to!(char[]);
  while(x){
    ushi~='3';
    x-=100;
  }

  writeln(ushi);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}



Measured memory_bytes: 2480
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a,b,q] <- getIntList
    ss <- VU.fromList <$> replicateM a getInt
    ts <- VU.fromList <$> replicateM b getInt
    xs <- replicateM q getInt
    let inf = 20000000000
    ans <- forM xs $ \x -> do
        let sridx = binarySearch x ss
            slidx = sridx - 1
            tridx = binarySearch x ts
            tlidx = tridx - 1
            sr | sridx == a = inf
               | otherwise = ss VU.! sridx
            sl | slidx == -1 = -inf
               | otherwise = ss VU.! slidx
            tr | tridx == b = inf
               | otherwise = ts VU.! tridx
            tl | tlidx == -1 = -inf
               | otherwise = ts VU.! tlidx
        let a1 = (max sr tr) - x
            a2 = (sr - x) * 2 + (x - tl)
            a3 = (x - tl) * 2 + (sr - x)
            a4 = x - (min sl tl) 
            a5 = (x - sl) * 2 + (tr - x)
            a6 = (tr - x) * 2 + (x - sl)
        return $ minimum [a1, a2, a3, a4, a5, a6]
    mapM_ print ans

binarySearch :: Int -> VU.Vector Int -> Int
binarySearch key vec = bs (-1) n
    where n = VU.length vec
          bs :: Int -> Int -> Int
          bs lidx ridx
            | ridx - lidx == 1 = ridx
            | midv >= key = bs lidx midx
            | midv <  key = bs midx ridx
            where midx = lidx + (ridx - lidx) `div` 2
                  midv = vec VU.! midx

Measured memory_bytes: 133056
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int1(input())
ans=[]
a=ord('a')
z=26
c=1
while N>=z:
    N-=z
    z*=26
    c+=1
while N:
    b=N%26
    ans.append(chr(b+a))
    if N<26:
        break
    N//=26
for _ in range(c-len(ans)):
    ans.append('a')
ans.reverse()
print(''.join(ans))

Measured memory_bytes: 61804
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BGreedyTakahashi {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, b, k; cin >> a >> b >> k;
      if (a > k) {
        a = a-k;
      } else {
        debug(b, k, a);
        b = max(b-(k-a), 0LL);
        a = 0;
      }
      cout << a << ' ' << b << endl;
    }
};

signed main() {
  BGreedyTakahashi solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);

        String text1 = sc.next();

        String text2 = sc.next();

        String[] ring = text1.split("", 0);

        String[] belt = text2.split("", 0);

        boolean check = false;
        for(int i = 0; i < ring.length; i++){
            if(belt[0].equals(ring[i])){
                int ring_check = i + 1;
                int count = 1;
                for(int j = 1; j < belt.length; j++){
                    if(ring_check >= ring.length){
                        ring_check = 0;
                    }
                    if(belt[j].equals(ring[ring_check])){
                        count++;
                        ring_check++;
                    }else{
                        break;
                    }
                }
                if(count == belt.length){
                    check = true;
                }
            }
        }
        if(check){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    
    deque<ll> ans;
    rep(i,n){
        ll a;cin>>a;
        if(i%2==0) ans.push_back(a);
        else ans.push_front(a);
    }

    if(n%2==0){
        rep(i,n){
            ll now=ans.front();
            ans.pop_front();
            cout<<now<<" ";
        }
    }else{
        rep(i,n){
            ll now=ans.back();
            ans.pop_back();
            cout<<now<<" ";
        }
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 5268
#include<bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define PB push_back
#define MP make_pair
#define I insert
 
const LL N = 51, mod = 1000000007;
 
using namespace std;
 
LL n, m, i, j, k, l, r, t, ans;
LL a[N], b[N], x[N], g[N][N], fix[N], fox[N];
vector < LL > v;

void clr (){
	for ( LL i = 0; i < N; ++i ){
		fox[i] = 0;
		for ( LL j = 0; j < N; ++j ){
			g[i][j] = 0;
		}
	}
}

void go ( LL u ){
	fix[u] = 1;
	for ( LL i = 0; i < u; ++i ){
		if ( fix[i] ) continue;
		if ( !g[u][i] ) continue;
		go ( i );
	}
}

int main(){
	x[0] = 1;
	for ( i = 1; i < N; ++i ) x[i] = x[i-1] << 1;
	
	cin >> n;
	for ( i = 0; i < n; ++i ){
		cin >> a[i];
	}
	for ( i = 0; i < n; ++i ){
		cin >> b[i];
	}
	for ( k = 51; k > 0; --k ){
		clr();
		for ( i = 0; i < N; ++i ){
			for ( j = 1; j < k; ++j ){
				g[i][i%j] = 1;
			}
			for ( j = 0; j < v.size(); ++j ){
				g[i][i%v[j]] = 1;				
			}
		}
		bool bb = true;/*/
		cout << k << "  ";
		for ( i = 0; i < n; ++i ){
			cout << a[i] << " ";
		}
		cout << endl;/**/
		for ( i = 0; i < n; ++i ){
			if ( a[i] == b[i] ) continue;
			for ( j = 0; j < N; ++j ) fix[j] = 0;
			go ( a[i] );
			if ( !fix[b[i]] ){
				bb = false;
				break;
			}
		}
		if ( bb ) continue;
		if ( k == 51 ){
			cout << "-1\n";
			return 0;
		}
		ans += x[k];
		v.PB(k);
	}
	cout << ans << endl;
	return 0;
}
 
/**/
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O        O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

    for i in range(len(s)):
        if s[i:] + s[:i] == t:
            print('Yes')
            return
    
    print('No')
    
    
solve()


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e3+11;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n;
        map<ll,ll> mp;
        for(i=2;i*i<=n;i++){
                ll c=0;
                while(n%i==0){
                        n/=i;
                        c++;
                }
                if(c){
                        mp[i]=c;
                }
        }
        if(n>1){
                mp[n]=1;
        }
        ll ans=0;
        for(auto x:mp){
                ll tt=1;
                while(((tt+1)*(tt+2))/2<=x.ss){
                        tt++;
                }
                ans+=tt;
        }
        cout<<ans<<endl;
        
        
      
       
}
int main(){
        FS;
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
int n, a[3][3], b[10];
bool appear[3][3];
 
int main() {
  rep(i,3) {
    rep(j,3) cin >> a[i][j];
  }
  cin >> n;
  rep(i,n) cin >> b[i];
  rep(i,n) {
      rep(j,n) {
        appear[i][j] = false;
        rep(k,n) {
          if(a[i][j] == b[k]) appear[i][j] = true;
        }
      }
    }
  string ans = "No";
  rep(i,3){
    if(appear[i][0] && appear[i][1] && appear[i][2]) ans = "Yes";
  }
  rep(i,3){
    if(appear[0][i] && appear[1][i] && appear[2][i]) ans = "Yes";
  }
  if(appear[0][0] && appear[1][1] && appear[2][2]) ans = "Yes";
  if(appear[0][2] && appear[1][1] && appear[2][0]) ans = "Yes";
  cout << ans << endl;
}

Measured memory_bytes: 3656
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9 + 7;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp.to!(char[]);

    long[26] as;

    foreach (c; S) {
        if (as[c-97] == 0) {
            as[c-97] = 2;
        } else {
            ++as[c-97];
        }
    }

    long r = 1;
    foreach (a; as) if (a) {
        r = (r * a) % P;
    }
    writeln(r-1);
}

Measured memory_bytes: 508
#include<bits/stdc++.h> 
using namespace std; 
int main() { 
int n , mx=0 , count=0;

scanf("%d", &n) ; 
char c[n];  
scanf("%s" , c) ; 
for(int i=0; i<n ; i++ ) { 
if (c[i]== 'I') { 

count++; 

mx=max(count,mx);
} 

else{
abs (count--);
}

}

printf("%d" , mx);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

#define MOD 1000000007

int main()
{
    ll N;
    INX(N);
    
    ll all = 1;
    ll non0or9 = 1;
    ll non0and9 = 1;
    for (ll i = 0; i < N; i++)
    {
        all *= 10;
        all %= MOD;
        non0or9 *= 9;
        non0or9 %= MOD;
        non0and9 *= 8;
        non0and9 %= MOD;
    }

    ll result = all - 2 * non0or9 + non0and9;
    result %= MOD;
    result = (result + MOD) % MOD;

    OUTX(result);
    


    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
int z[9999],r[9999];
int f(int a,int b){
	fflush(!printf("? %d %d\n",a,b));
	char c[2];
	scanf("%s",c);
	return*c=='Y';
}
int main(){
	int a,b,c=0,h,i;
	if(scanf("%d%d",&a,&b),a<=b){puts("Impossible");return 0;}
	for(i=a+=b;~--i;)!c||f(i,z[c-1])?(z[c++]=i):c--;
	for(h=*z,i=a;~--i;)r[i]=f(h,i);
	for(printf("! "),i=0;i<a;)printf("%d",r[i++]);
	puts("");
}

Measured memory_bytes: 720
/*

Author : @karngyan
Team : BlundersPride
Date : 09-03-2019
Time : 05:20:14

*/


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
ll a[25][25];

signed main()
{
	fast;
////////////////////////////////////////////////////////////////////////////////////////////
memset(a , 0 , sizeof a);
ll h , w;
cin >> h >> w;
ll r , c ;
cin >> r >> c;

ll ans = 0;
rep(i,0,r)
{
	rep(j,0,w)
	{
		a[i][j] = 1;
	}
}

rep(j,0,c)
{
	rep(i,0,h)
	{
		a[i][j] = 1;
	}
}

rep(i,0,h)
{
	rep(j,0,w)
	{
		if(a[i][j] == 0)
			ans++;
	}
}
cout<<ans<<endl;








////////////////////////////////////////////////////////////////////////////////////////////
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;
// 0 :Ú®Â\Å é
// 1 :áQ¨ª é
// 2 :Wväª é
int field[15+1][15];
int memo[15+1][15];
int main()
{
	const int dir[][2] = {  { 1, -1 }, { 1, 0 }, { 1, 1 } };
//	cut here before submit 
//	freopen ("testcase.new_plan", "r", stdin );
	int X, Y;

	while (cin >> X >> Y && X && Y ){
		memset (field, 0, sizeof (field ) );
		memset (memo, 0, sizeof (memo) );

		for (int i = 0; i < Y; ++i ){
			for (int j = 0; j < X; ++j ){
				cin >> field[i][j];
			} // end for
		} // end for
		
		for (int j = 0; j < X; ++j ){ 
			field[Y][j] = 0;
			memo[Y][j] = 1;
		} // end for

		for (int j = 0; j < X; ++j ){
			if (field[Y-1][j] == 0 || field[Y-1][j] == 2 ){
				memo[Y-1][j] = 1;
			} // end if
		} // end for
		
		for (int i = Y - 2; i >= 0 ; --i ){
			for (int j = 0; j < X; ++j ){
				if (field[i][j] == 1 ){
					continue;
				}else
				if (field[i][j] == 0 ){
					for (int k = 0; k < 3; ++k ){
						int ny = i + dir[k][0];
						int nx = j + dir[k][1];
						if (nx < 0 || nx >= X ){
							continue;
						} // end if
						if (field[ny][nx] == 1 ){
							continue;
						} // end if
						if ((k == 0 || k == 2) && field[ny][nx] == 2 ){
							continue;
						} // end if
						if (field[ny][nx] == 2 && field[ny+2][nx] == 1 ){
							continue;
						} // end if
						memo[i][j] += memo[ny][nx];
					} // end for
				}else{ // if (field[i][j] == 2 )
					if (field[i+2][j] != 1 ){
						memo[i][j] += memo[i+2][j];
					} // end for
				} // end if
			} // end for
		} // end for
		
		int res = 0;
		for (int j = 0; j < X; ++j ){
			res += memo[0][j];
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
use std::char;
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}
fn main() {
    let mut n = get_one!(isize);

    let mut res = vec![];

    while n > 0 {
        let r = n % 26;
        if r == 0 {
            res.push(26);
            n = n / 26 - 1;
        } else {
            res.push(r);
            n = n / 26;
        }
    }

    res.reverse();

    let ans: String = res.into_iter().map(|i| char::from_u32((i + 0x60_isize) as u32).unwrap()).collect();

    println!("{}", ans);

}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)

int main(){
    char a,b;
    cin >> a >> b;
    if(a=='H'){
        cout << (b=='H'?'H':'D') << endl;
    }else if(a=='D'){
        cout << (b=='D'?'H':'D') << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get() {}template<class H, class...T>void get(H&h, T&...t) { cin >> h; get(t...); }
template<class T>void geti(T&a) { for (auto&_ : a)cin >> _; }
template<class T>void getii(T&a) { for (auto&_ : a)geti(_); }
void put(string d) {}template<class H, class...T>void put(string d, H&h, T&...t) { cout << h; if (sizeof...(t))cout << d; put(d, t...); }
template<class T>void puti(T&a, string d = " ") { bool f = 1; for (auto&_ : a)cout << (exchange(f, 0) ? "" : d) << _; cout << endl; }
template<class T>void putii(T&a, string d = " ") { for (auto&_ : a)puti(_, d); }
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)


int main() {
    int n;
    cin >> n;
    int s = -INF;
    int min = INF;
    vi v(n, 0);
    geti(v);
    rep(i, n-1) {
        if (s < v[i + 1] - v[i]) {
            s = v[i + 1] - v[i];
        }
        if (v[i] < v[i + 1]) {
            if (min > v[i]) {
                min = v[i];
                range(j, i + 1, n) {
                    if (s < v[j] - v[i]) {
                        s = v[j] - v[i];
                    }
                }
            }
        }
    }
    cout << s << endl;
}



Measured memory_bytes: 3624
fn main() {
    let n = read::<u32>();

    let mut x = n;
    loop {
        if is_prime(x) {
            println!("{}", x);
            break;
        }
        x += 1
    }
}

fn is_prime(n: u32) -> bool {
    n != 1 && (2..).take_while(|x| x * x <= n).all(|x| n % x != 0)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include <functional>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> cards(n);
	for (int i = 0; i < n; i++) cin >> cards[i];
	sort(cards.begin(), cards.end(), greater<int>());
	int alice = 0, bob = 0;
	for (int i = 0; i < n; i++) {
		(i % 2 == 0 ? alice : bob) += cards[i];
	}

	int ans = alice - bob;
	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
typedef pair<int,int> P;
 
bool check(int a,int b,int c)
{
  int v = b*b-4*a*c;
  if(v < 0)return false;
  int vs = (int)sqrt(v);
  if(vs*vs != v)return false;
  return true;
}
 
bool cmp(const P &a,const P &b)
{
  if(a.first != b.first)return a.first > b.first;
  return a.second > b.second;
}
 
int main()
{
  int a,b,c;
  while(cin >> a >> b >> c,a|b|c)
    {
      if(!check(a,b,c))
    {
      cout << "Impossible" << endl;
      continue;
    }
      int s1,s2,aa,ab;
      aa = ab = 2*a;
      s1 = -(-b+sqrt(b*b-4*a*c));
      s2 = -(-b-sqrt(b*b-4*a*c));
      //cout << s1 << " x " << s2 << endl;
      int gcd1 = __gcd(s1,aa);
      int gcd2 = __gcd(s2,ab);
      //cout << "gcd = " << gcd1 << " " << gcd2 << endl;
      if(gcd1 != 1)s1 /= gcd1,aa /= gcd1;
      if(gcd1 != 1)s2 /= gcd2,ab /= gcd2;
      //cout << s1/aa << " " << s2/ab << endl;
      //cout << "ss = " << s1 << " " << s2 << endl;
      //cout << "aa = " << aa << " " << ab << endl;
      vector<P> vec(2,P(0,0));
      vec[0].first = aa,vec[0].second = s1;
      vec[1].first = ab,vec[1].second = s2;
      if(vec[0].first < 0)vec[0].first*=-1,vec[0].second*=-1;
      if(vec[1].first < 0)vec[1].first*=-1,vec[1].second*=-1;
 
      
      sort(vec.begin(),vec.end(),cmp);
      cout << vec[0].first << " " << vec[0].second << " " << vec[1].first << " " << vec[1].second << endl;
    }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,v[2001],ans,money,stocks;
pll dp[81][2];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    money=1000;
    for(int i=1;i<n;i++)
    {
        stocks=0;
        if(v[i]<v[i+1])
            stocks=money/v[i];
        money+=(v[i+1]-v[i])*stocks;
    }
    cout<<money;
    return 0;
}


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

int main(){
    std::string tmp;
    std::cin >> tmp;
    int num[4];
    for(int i = 0; i < 4; i++) num[i] = tmp[i] - '0';

    // bitが立ってたら+, そうでなければ-
    for(int bit = 0; bit < (1 << 3); bit++){
        int sum = 0;
        std::string S;
        S += '0' + num[0];
        sum += num[0];
        for(int i = 0; i < 3; i++){
            if(bit & (1 << i)){
                sum += num[i + 1];
                S += "+";
            }else{
                sum -= num[i + 1];
                S += "-";
            }
            S += '0' + num[i + 1];
        }

        if(sum == 7){
            std::cout << S << "=7" << std::endl;
            return 0;
        }
    }
    return 0;
}


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

ll N, A, B;

int main() {
  cin >> N >> A >> B;
  ll ans = (N / (A+B)) * A;
  if (N % (A+B) > A) ans += A;
  else ans += N % (A+B);
  cout << ans << endl;
}

Measured memory_bytes: 256