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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< int > S(1 << N);
    cin >> S;

    map< int, int > cnt;
    range(i, 0, 1 << N) {
        cnt[-S[i]]++;
    }

    priority_queue< int > sz;
    sz.push((1 << N) * 2 - 1);
    
    for (auto p: cnt) {
        int a, cnt;
        tie(a, cnt) = p;
        
        if (sz.size() < cnt) {
            cout << "No" << endl;
            return;
        }
        
        vector< int > use(cnt);
        range(i, 0, cnt) {
            use[i] = sz.top();
            sz.pop();
        }

        for (auto &m: use) {
            while (m != 1) {
                sz.push(m / 2);
                m /= 2;
            }
        }
    }

    cout << "Yes" << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 14204
#include <stdio.h>

int main(void){

        int n,i,b,f,r,v=0,a[4][3][10]={0};
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%d %d %d %d",&b,&f,&r,&v);
                a[b-1][f-1][r-1]+=v;
        }

        for(b=0;b<4;b++){
                for(f=0;f<3;f++){
                        for(r=0;r<10;r++)
                                printf("%2d",a[b][f][r]);
                        puts("");
                        }
                if(b!=3)        puts("####################");
        }
        return 0;
}

Measured memory_bytes: 1740
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll a, b, c, k; cin >> a >> b >> c >>k;
  ll ans = 0;
  if(a >= k)
  {
    fin(k);
  }
  else if(a + b >= k)
  {
    fin(a);
  }
  else
  {
    fin(a - (k - a - b));
  }
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 3632
n = int(input())
a, b = [int(i) for i in input().split()]
ps = sorted([int(i) for i in input().split()])
x, y, z = 0, 0, 0
for p in ps:
    if p <= a:
        x += 1
    elif a < p <= b:
        y += 1
    else:
        z += 1
print(min(x, y, z))

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

int main(){
    int x = 700;
    string y;
    cin >> y;
    for(int i = 0; i < 3; i++)
    {
        if (y[i] == 'o') {
            x += 100;
        }
        
    }
    cout << x << endl;
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
LL a[100];
int n;

LL solve(int x){
	if(x == 0) return a[0];
	else if(x == 1) return a[1];
	if(a[x] == 0) a[x] = solve(x - 1) + solve(x - 2);
	return a[x];
}

int main(){
	a[0] = 2LL, a[1] = 1LL;
	scanf("%d", &n);
	printf("%lld\n", solve(n));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, a, b, c, x, y;
int main()
{
    cin>>a>>b>>c>>x>>y;
    cout<<min(a*x+b*y,
        min(c*2*min(x, y)+(x>y?(x-y)*a:(y-x)*b), c*2*max(x,y)))<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <string>

using namespace std;

void upcase(string& s) {
  for (int i = 0; i < s.length(); i++)
    if (islower(s[i])) s[i] -= 32;
  return;
}

int main() {
  string str;
  getline(cin, str);
  upcase(str);
  cout << str <<endl;
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    string str;
    cin >> str;
    int a=1,b=1;
    if(str.find("N")+1||str.find("S")+1){
        if(str.find("N")+1&&str.find("S")+1)a=1;
        else a=0;
    }    
    if(str.find("W")+1||str.find("E")+1){
        if(str.find("W")+1&&str.find("E")+1)b=1;
        else b=0;
    }
    cout << (a&&b?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            int H1 = cin.nextInt();
            int M1 = cin.nextInt();
            int H2 = cin.nextInt();
            int M2 = cin.nextInt();
            int K = cin.nextInt();

            int x1 = H1 * 60 + M1;
            int x2 = H2 * 60 + M2 -1;

            int ans = x2 - x1 - K;
            Console.WriteLine(Math.Max(0, ans + 1));
        }
    }
}


Measured memory_bytes: 27836
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
string c;

int main()
{
    int n;char d;int t=1;
    string c;
    map<string,bool> a;
    cin>>n;
    for(int i=0;i<n;i++)
    {

        cin>>c;
        if(i)
            if(d!=c[0])
                t=0;
        if(a[c])
            t=0;
        a[c]=1;
        d=c[c.size()-1];
    }
    if(t)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
import itertools
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))

A[0] %= M
ct = Counter(itertools.accumulate(A, lambda x, y: (x + y) % M))
ans = ct[0]
for value in ct.values():
    ans += (value * (value - 1)) // 2
print(ans)


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

#define int 		long long
#define ld 			long double
#define ull 		unsigned long long
#define endl 		"\n"
#define f(i,z,n) 	for(int i=z;i<n;i++)
#define fd(i,x,n) 	for(int i=n;i>=x;i--)
#define ains(a,n)  	f(i,0,n) cin>>a[i];
#define vins(v,n)	f(i,0, n) {cin >> x; v.pb(x);}
#define w(t)		int t; cin>>t; while(t--)
#define all(x)		(x).begin(),(x).end()
#define Sort(x)		sort(all(x))
#define pb 			push_back
#define mp 			make_pair
#define vi 			vector<int>
#define vc 		   	vector<char>
#define mii 		map<int,int>
#define si 			set<int>
#define sc 			set<char>
#define pii			pair<int,int>
#define setbits(n)  __builtin_popcountint(n)
#define mod			1000000007
#define FIO 		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

// Returns value of Binomial Coefficient C(n, k)
int binomialCoeff(int n, int k)
{
	int res = 1;

	// Since C(n, k) = C(n, n-k)
	if ( k > n - k )
		k = n - k;
	f(i, 0, k)
	{
		res *= (n - i);
		res /= (i + 1);
	}

	return res;
}
//Catalan number 1/n+1(C(2n,n))
ull Catalan(unsigned int n)
{
	ull c = binomialCoeff(2 * n, n);
	return c / n + 1;
}
//***************************************************************************************************//

int32_t main() {
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int k, a, b;
	cin >> k;
	cin >> a >> b;
	bool f = false;
	f(i, a, b + 1)
	{
		if (i % k == 0)
		{
			f = true;
			break;
		}
	}
	cout << (f == 1 ? "OK" : "NG");
	return 0;
}

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

int main(){
  char b;cin>>b;
  if(b=='A')cout<<'T';
  if(b=='T')cout<<'A';
  if(b=='G')cout<<'C';
  if(b=='C')cout<<'G';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

#define MAX_N 101

int route[MAX_N];

int main()
{
    int a,b=1;
    int n=0;
    bool flag=false;
   
    while (cin >> a && cin >> b)
    {
        route[a]++;//頂点 a の次数を増やす;
        route[b]++;//頂点 b の次数を増やす;
        n++;
        if (a == 0)
        {
            //始点から終点に一筆書き出来るか (*) を判定して出力
                //(*) 頂点番号 1 と 2 の字数が奇数,かつ,
                    //頂点番号 3 以上の頂点の次数が全て偶数
            if(route[1] % 2 == 0 || route[2] % 2 == 0){ flag=true; }
            for(int i=3; i<=n; i++){ if(route[i]%2==1){ flag=true; } }
                
            if(flag){cout << "NG" << endl;}
            else{cout << "OK" << endl;}
            //次のテストケースのために,全ての頂点の次数を 0 に戻す
            for(int i=0; i < MAX_N; i++){route[i]=0;}
            n=0; flag=false;
        }
    }
}

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

int main(int argc, char const *argv[]) {
    int a,b;
    cin >> a >> b;

    int ans = 0;
    int socket = 1;
    while (socket < b) {
        --socket;
        socket += a;
        ++ans;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N,M,K;

int main(){

    cin >> N;
    vector<int> R;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        R.push_back(tmp);
    }


    sort(R.begin(),R.end());
    double ans=(R[0]+R[1]);
    ans /= 2;
    if(N>=3){
        for(int i=2;i<N;i++){
         ans =(ans+R[i])/2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define MAX 100010
#define INF 100000000

bool visited[MAX] = {0};
vector<int> G[MAX];
int high[MAX], low[MAX], ans[MAX];

bool dfs(int i, int a) {
    //cerr << i << ' ' << low[i] << ' ' << high[i] << ' ' << a << '\n';
    ans[i] = a;
    visited[i] = true;  
    for (auto g:G[i]) {
        if (visited[g]) continue;
        if (low[g] <= a-1 && a-1 <= high[g]) {
            if (!dfs(g, a-1)) {
                return false;
            }
        }
        else if (low[g] <= a+1 && a+1 <= high[g]) {
            if (!dfs(g, a+1)) {
                return false;
            }
        }
        else
            return false;
    }
    return true;
}

struct node {int v, p;};

int main() {
    int n;
    cin >> n;
    for (int i=0, a, b; i<n-1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int k;
    cin >> k;
    int v, p;
    queue<node> qh, ql;
    fill(high, high+n, INF);
    fill(low, low+n, -INF);
    for (int i=0; i<k; i++) {
        cin >> v >> p;
        v--;
        high[v] = low[v] = p;
        qh.push(node{v, p});
        ql.push(node{v, p});
    }
    while (!qh.empty()) {
        node f = qh.front(); qh.pop();
        for (auto g:G[f.v]) {
            if (high[g] > f.p + 1) {
                high[g] = f.p + 1;
                qh.push(node{g, high[g]});
            }
        }
    }
    while (!ql.empty()) {
        node f = ql.front(); ql.pop();
        for (auto g:G[f.v]) {
            if (low[g] < f.p - 1) {
                low[g] = f.p - 1;
                ql.push(node{g, low[g]});
            }
        }
    }
    fill(ans, ans+n, -1);
    visited[v] = true;
    if (dfs(v, p)) {
        cout << "Yes" << '\n';
        for (int i=0; i<n; i++) cout << ans[i] << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans = 0;
    for(int i=a;i<=b;++i){
        if(c%i==0){
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll s = 0;
    ll t = 0;
    vector<int> x,y;
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(a[i]>=0){
                x.push_back(i);
                s += a[i];
            }
        }else{
            if(a[i]>=0){
                y.push_back(i);
                t += a[i];
            }
        }
    }
    if(x.size()==0&&y.size()==0){
        ll ma = -inf;
        int tmp = -1;
        rep(i,n){
            if(ma<a[i]){
                ma = a[i];
                tmp = i;
            }
        }
        cout << ma << endl;
        cout << n-1 << endl;
        for(int i=n;i>tmp+1;i--){
            cout << i << endl;
        }
        for(int i=1;i<=tmp;i++){
            cout << 1 << endl;
        }
    }else{
        if(t>s){
            x = y;
            s = t;
        }
        if(x.size()==1){
            cout << a[x[0]] << endl;
            cout << n-1 << endl;
            for(int i=n;i>x[0]+1;i--){
                cout << i << endl;
            }
            for(int i=1;i<=x[0];i++){
                cout << 1 << endl;
            }
        }else{
            cout << s << endl;
            int tmp = x[0] + n-x[x.size()-1]-1;
            cout << tmp + (n-tmp)/2 << endl;
            for(int i=n;i>x[x.size()-1]+1;i--){
                cout << i << endl;
            }
            for(int i=0;i<x[0];i++){
                cout << 1 << endl;
            }
            for(int i=1;i<x.size();i++){
                int k = x[i]-x[i-1];
                k /=2;
                for(int j=0;j<k-1;j++){
                    cout << 3 << endl;
                }
                cout << 2 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
# じょえチャンネルおもしろいよ～～～
# https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ

x,y=map(int,input().split())
if y%2==1:exit(print("No"))
if 2*x<=y<=4*x:print('Yes')
else:print('No')

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

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

    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();

    s += s;
    ll a=0,b=0;
    bool all_same = false;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            all_same = true;
            break;
        }
    }
    rep(i,n-1){
        if(s[i]==s[i+1]){
            a++;
            s[i+1] = '#';
        }
    }

    for(int i=n-1;i<2*n-1;i++){
        if(s[i]==s[i+1]){
            b++;
            s[i+1] = '#';
        }
    }
    if(all_same) cout << a+b*(k-1) << "\n";
    else cout << n*k/2 << "\n";
    return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>                                                                                                    
                                                                                                                      
void main()                                                                                                           
{                                                                                                                     
    char c[6];                                                                                                        
    scanf("%s", &c);                                                                                                  
                                                                                                                      
    if (c[2] == c[3] && c[4] == c[5] )                                                                                
        printf("Yes");                                                                                                
    else                                                                                                              
        printf("No");                                                                                                 
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    rep(i,s.size()){
        s[i] = (s[i] - 'A' + n)%26 + 'A';
    }
    cout << s << endl;
}

Measured memory_bytes: 3596
w = input()
n = input()
line = [[0 for i in xrange(n)] for j in xrange(w + 1)]
for i in xrange(n):
    a, b = map(int, raw_input().split(','))
    line[a][i] = b
    line[b][i] = a
for i in xrange(1, w + 1):
    num = i
    for j in xrange(n - 1, -1, -1):
        if line[num][j] > 0: num = line[num][j]
    print num

Measured memory_bytes: 6348
n,a=map(int,input().split())
x=list(map(int,input().split()))

xmax=max(max(x),a)
    
nx=n*xmax
dp=[[[0]*(nx+1) for ii in range(n+1)] for i in range(n+1)]

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

for j in range(1,n+1):
    jj=j-1
    for k in range(n+1):
        for s in range(nx+1):
            if s<x[jj]:
                dp[j][k][s]=dp[j-1][k][s]
            elif 1<=k and  x[jj]<=s:
                dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[jj]]
            else:
                dp[j][k][s]=0
#            if dp[j][k][s]!=0:
#                print(j,k,s,dp[j][k][s])
dpsum=0
for k in range(1,n+1):
    dpsum=dpsum+dp[n][k][k*a]
                
print(dpsum)
        


Measured memory_bytes: 93148
n = input()
n0 = int(n[0])
n1 = int(n[1])
n2 = int(n[2])


if max(n0, n1, n2) == n0 or n2 >= n0 > n1:
    print(n[0]*3)
else:
    print(str(n0 + 1)*3)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cost[100002], n, k;
ll dp[100002];
ll jump(ll pos)
{
    if(dp[pos]!=-1)
    return dp[pos];
    if(pos == n)
    return 0;
    if(pos > n)
    return INT_MAX;
    ll ans = 0, prev = INT_MAX;
        for(ll i = 1; i<=k; i++){
            ans = (abs(cost[pos] - cost[pos+i]) +  jump(pos+i));
            prev = min(prev, ans);
        }   
    return dp[pos] = prev;
}



int main(){
    cin >> n >> k;
    memset(dp, -1, sizeof(dp));
    for(int i = 1; i<=n; i++)
        cin >> cost[i];
    ll ans = jump(1);
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
  static long mod = 1000000007;

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a = scan.nextInt();
    int b = scan.nextInt();
    scan.close();

    long ans = power(2, n) - nCk(n, a) - nCk(n, b) - 1;
    while(ans < 0) {
      ans += mod;
    }
    System.out.println(ans);
  }

  public static long power(long x, long n) {
    long result = 1;
    while(n > 0) {
      if(n%2 == 1) {
        result *= x;
        result %= mod;
      }
      x = x*x;
      x %= mod;

      n >>= 1;
    }

    return result;
  }

  public static long nCk(long n, long k) {
    long up = 1;
    for(long i=n-k+1; i<=n; i++) {
      up *= i;
      up %= mod;
    }
    long bottom = 1;
    for(long i=1; i<=k; i++) {
      bottom *= i;
      bottom %= mod;
    }

    return up * power(bottom, mod-2) % mod;
  }
}

Measured memory_bytes: 23892
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

const double EPS=1e-7; // EPS=1e-8 だと誤差で間違う
const double INF=1e77;
const double PI=acos(-1);

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point &operator+=(const point &a){ x+=a.x; y+=a.y; return *this; }
	point &operator-=(const point &a){ x-=a.x; y-=a.y; return *this; }
	point &operator/=(double c){ x/=c; y/=c; return *this; }
	point operator+(const point &a)const{ return point(x+a.x,y+a.y); }
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
	bool operator< (const point &a)const{ return x+EPS<a.x || abs(x-a.x)<EPS && y+EPS<a.y; }
};

double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

double abs(const point &a){ return sqrt(a.x*a.x+a.y*a.y); }

double arg(const point &a){ double t=atan2(a.y,a.x); return t<0?t+2*PI:t; }

point rot(const point &a,double theta){ return point(a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)); }

typedef vector<point> polygon;

enum{CCW=1,CW=-1,ON=0};
int ccw(const point &a,const point &b,const point &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

polygon convex_hull(vector<point> &P){
	int n=P.size();
	polygon CH;
	if(n<=1){
		CH.insert(CH.end(),P.begin(),P.end());
		return CH;
	}
	sort(P.begin(),P.end());

	rep(_,2){
		int m=0;
		vector<point> half(n);
		rep(i,n){
			half[m++]=P[i];
			while(m>=3 && ccw(half[m-3],half[m-2],half[m-1])==CW){
				half[m-2]=half[m-1];
				m--;
			}
		}
		CH.insert(CH.end(),half.begin(),half.begin()+m-1);
		reverse(P.begin(),P.end());
	}

	return CH;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<point> P(n),Q(n);
		rep(i,n) scanf("%lf%lf",&P[i].x,&P[i].y);
		rep(i,n) scanf("%lf%lf",&Q[i].x,&Q[i].y);

		if(n==1){
			puts("0");
			continue;
		}

		polygon F=convex_hull(P);
		polygon G=convex_hull(Q);

		set<point> S(Q.begin(),Q.end());

		double ans=INF;
		rep(_,2){
			rep(i,G.size()){
				point v=G[i]-F[0];
				double theta=arg(G[(i+1)%G.size()]-G[i])-arg(F[1]-F[0]);

				bool ok=true;
				rep(j,n){
					if(S.count(rot(P[j]-F[0],theta)+F[0]+v)==0){
						ok=false;
						break;
					}
				}
				if(ok){
					theta=abs(theta);
					while(theta>2*PI) theta-=2*PI;
					ans=min(ans,theta);
					ans=min(ans,2*PI-theta);
				}
			}
			reverse(G.begin(),G.end());
		}
		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1296
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/27/20 20:37:13
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,m,k; cin>>n>>m>>k;
  vector<int> A(n); for (auto& a:A) cin>>a;
  vector<int> B(m); for (auto& b:B) cin>>b;
  int ans = 0;
  int na = 0;
  int nb = m;
  ll sum = accumulate(B.begin(), B.end(), 0ll);
  while (na <= n) {
    while (nb and sum > k) {
      sum -= B[nb-1];
      nb--;
    }
    ans = max(ans, na+nb);
    if (na < n) {
      sum += A[na];
    }
    if (sum > k and nb == 0)
      break;
    na++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    string s,t;
    cin>>s>>t;
    int ans=1000;
    for(int i=0;i<=s.size()-t.size();i++){
        int cnt=0;
        for(int j=0;j<t.size();j++)
            if(s[i+j]!=t[j])
                cnt++;
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

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

const int INF = 1e9;

int main() {
  long long x,y;
  cin>>x>>y;
  long cnt=1;
  long long val=x;
  while(true){
    if(2*val<=y){
      ++cnt;
      val=2*val;
    }else{
      break;
    }
  }
  cout<<cnt<<endl;


}

Measured memory_bytes: 256
#!/usr/bin/ruby                                                                                                  
# -*- coding: utf-8 -*-                                                                                          

s = gets.split(' ').map{|x| x.to_i}.reduce(:+)
t = gets.split(' ').map{|x| x.to_i}.reduce(:+)
puts "%d" % (s > t ? s : t)

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int limit = 200010;
int nxt[26][limit];
string s;
int n, ans[limit], len[limit];


void calc(int pos) {
	int nidx = -1, cmin = limit;

	rep(i, 26) {
		const int tar = nxt[i][pos + 1];

		if (tar == -1) {
			nidx = n + i;
			cmin = 1;
			break;
		} else {
			if (len[tar] == 0) calc(tar);
			if (chmin(cmin, len[tar])) nidx = tar;
		}
	}
	ans[pos] = nidx, len[pos] = cmin + 1;
}

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

	rep(i, 26)rep(j, limit) nxt[i][j] = -1;
	rep(i, n) nxt[s[i] - 'a'][i] = i;

	rep(i, 26)rrep(j, n - 1) {
		if (nxt[i][j] != -1) continue;
		nxt[i][j] = nxt[i][j + 1];
	}

	s += "abcdefghijklmnopqrstuvwxyz";

	int cur = 0,cmin = limit;
	rep(i, 26) {
		const int tar = nxt[i][0];
		if (tar == -1) {
			cout << char(i + 'a') << endl;
			return 0;
		}else{
			if (len[tar]== 0) calc(tar);
			if(chmin(cmin,len[tar])) cur = tar;
		}
	}

	string out = "";
	while(1){
		out += s[cur];
		if(cur >=n) break;
		cur = ans[cur];
	}

	cout << out << endl;

	return 0;
}

Measured memory_bytes: 23044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[10000007];

int main(){
  ll n;
  cin >> n;
  ll sum = 1;
  rep(i,n){
    sum *= 3;
  }
  vl a(n);
  ll sub = 1;
  rep(i, n){
    cin >> a[i];
    if(a[i]%2==0){
      sub *= 2;
    }
  }
  print(sum - sub);
}

Measured memory_bytes: 3568
char buf[5],out[2<<17];
sz,outsz;
i,j;
N;
main(){
	read(0,buf,5);
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;i++<N;)for(j=i;j++<N;)
	{
		out[outsz++]=__builtin_ffs(i^j)+'0';
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.IOException;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Denis Nedelyaev
 */
public class Main {
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtA solver = new AtA(in, out);
        solver.solve(1);
        out.close();
    }

    static class AtA {
        private final FastScanner in;
        private final PrintWriter out;

        public AtA(FastScanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solve(int testNumber) throws IOException {
            String s = in.next();
            boolean[] used = new boolean[256];
            for (char c : s.toCharArray()) {
                used[c] = true;
            }
            if (used['S'] != used['N'] || used['W'] != used['E']) {
                out.println("No");
            } else {
                out.println("Yes");
            }
        }

    }

    static class FastScanner {
        private final BufferedReader br;
        private String line;
        private int pos;

        public FastScanner(String s) throws IOException {
            this(new StringReader(s));
        }

        public FastScanner(InputStream is) throws IOException {
            this(new InputStreamReader(is, "UTF-8"));
        }

        public FastScanner(Reader reader) throws IOException {
            this(new BufferedReader(reader));
        }

        public FastScanner(BufferedReader reader) throws IOException {
            br = reader;
            line = br.readLine();
            pos = 0;
        }

        public String next() throws IOException {
            if (!skipWhitespace()) {
                return null;
            }

            int start = pos;

            while (pos < line.length()) {
                char c = line.charAt(pos);

                if (c == ' ' || c == '\t') {
                    break;
                }

                pos++;
            }

            return line.substring(start, pos);
        }

        private boolean skipWhitespace() throws IOException {
            while (line != null) {
                while (pos < line.length()) {
                    char c = line.charAt(pos);

                    if (c != ' ' && c != '\t') {
                        return true;
                    }

                    pos++;
                }

                line = br.readLine();
                pos = 0;
            }

            return false;
        }

    }
}



Measured memory_bytes: 8148
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;


#define FASTIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt", "w+", stdout)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define DBG printf("hey!!!\n")
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))



typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;



const ll MAX= 998244353;
const ll MAX2=1271309838631957LL;
long double PI = acosl(-1);
const ll INF = 1e15;
const int NMAX = 2e5+5;
const int MAXLG = log2(NMAX)+1;
const int oo = 1e9+10;
const int sz = 100005;
const int MOD = 10000019;
const double EPS = 1e-9;

/// code starts from here

void solve(){
    int n;
    vector<int> v;

    cin >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }


    int dp[NMAX];
    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);

    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout << dp[n-1] << endl;
}

int main(){
    //IN;
    FASTIO;

    solve();




}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define MAX_N 500000

ll f[MAX_N], invf[MAX_N];
ll p = 1e9 + 7;

ll mod_pow(ll x, ll n, ll p)
{
    if (n == 0)
        return 1;
    ll res = mod_pow(x * x % p, n / 2, p);
    if (n & 1)
        res = res * x % p;
    return res;
}

void init()
{
    f[0] = 1;
    invf[0] = 1;
    for (ll i = 1; i <= MAX_N - 10; i++)
    {
        f[i] = f[i - 1] * i % p;
        invf[i] = (mod_pow(i, p - 2, p) * invf[i - 1]) % p;
    }
}

ll mod_conv(ll n, ll k)
{
    ll tmp = invf[n - k] * invf[k] % p;

    return f[n] * tmp % p;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    init();
    ll ans = mod_pow(2, n, p) - 1;

    ll ma = 1, mb = 1;

    for (ll i = 0; i < a; i++)
        ma = ma * (n - i) % p;
    ma = ma * invf[a] % p;
    for (ll i = 0; i < b; i++)
        mb = mb * (n - i) % p;
    mb = mb * invf[b] % p;

    ans = (ans - ma - mb + 2 * p) % p;
    OP(ans);

    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
	ll x;
	cin >> x;
	ll ans = 2*(x/11);
	if(x%11 >= 7) ans += 2;
	else if(x%11 > 0) ans += 1;
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
int main()
{
	ll a,b,n;
	cin >> a >> b >> n;
	ll l = 0, r = n;
	ll ans = INT_MIN;
	while(l <= r){
		ll mid = l+(r-l)/2;
		ll res = (a*mid)/b-a*(mid/b);
		if(res >= ans){
			l = mid+1;
			ans = res;
		}
		else r = mid-1;
	}
	cout << ans;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=2e3+10;
	//------------------FIXED------------------
	ll pp[N];
	ll solve(ll T,ll x1,ll y1,ll x2,ll y2)
	{
		ll xx1=x1/T,yy1=y1/T,xx2=x2/T,yy2=y2/T;
		if(xx1==xx2 and yy1==yy2) return solve(T/3,x1,y1,x2,y2);
		if(xx1==xx2 and xx1%3==1 and abs(yy1-yy2)>=2) {x1%=(T*3),x2%=(T*3);return min(x1+x2-(T-1)*2,(T+T)*2-x1-x2)+abs(y1-y2);}
		if(yy1==yy2 and yy1%3==1 and abs(xx1-xx2)>=2) {y1%=(T*3),y2%=(T*3);return min(y1+y2-(T-1)*2,(T+T)*2-y1-y2)+abs(x1-x2);}
		if(T==1) return abs(x1-x2)+abs(y1-y2);
		else return solve(T/3,x1,y1,x2,y2);
	}
	void main()
	{
		pp[0]=1;fo(i,1,30) pp[i]=pp[i-1]*3;
		fo(q,1,qread())
		{
			ll x1=qread()-1,y1=qread()-1,x2=qread()-1,y2=qread()-1;
			write2( solve(pp[29],x1,y1,x2,y2) );
		}
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	freopen("a.in","r",stdin);
	//freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 23808
import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
}

Measured memory_bytes: 24404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_Cs
{
    public class Program
    {
        public static void Main()
        {
            var N = long.Parse(Console.ReadLine());
            long ret = N;


            for (long i = 1;i * i <= N;i++)
            {
                if (N % i == 0)
                {
                    long r = (i - 1) + (N / i) - 1;
                    if(r < ret) { ret = r; }
                    //break;
                }
            }

            Console.WriteLine($"{ret}");
        }
    }

}


Measured memory_bytes: 13268
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
for i in range(n):
    for j in range(i + 1, n):
        ans[min(j - i, abs(i - (x - 1)) + 1 + abs(j - (y - 1)), abs(j - (x - 1)) + 1 + abs(i - (y - 1))) - 1] += 1
for a in ans:
    print(a)

Measured memory_bytes: 47196
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,x,ans;
int main()
{
    cin>>a>>b>>c>>x;
    for (int i=0;i<=a&&500*i<=x;i++)
        for (int j=0;j<=b&&100*j+500*i<=x;j++)
            for (int k=0;k<=c&&50*k+100*j+500*i<=x;k++)
                if (500*i+100*j+50*k==x)
                    ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 800010
#define ll long long
const double pi=acos(-1);
typedef complex<double> cp;
        int n,rev[maxn];
        cp omega[maxn],iomega[maxn];
        void init(int N)
        {
                n=N;
                for(int i=0;i<n;i++)
                {
                        omega[i]=cp(cos(2*pi/n*i),sin(2*pi/n*i));
                        iomega[i]=conj(omega[i]);
                }
                int k=log2(n);
                for(int i=0;i<n;i++)
                {
                        int t=0;
                        for(int j=0;j<k;j++)if(i&(1<<j))t|=(1<<(k-j-1));
                        rev[i]=t;
                }
        }
        void transform(vector<cp>& a,cp* omega)
        {
                for(int i=0;i<n;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
                for(int len=2;len<=n;len<<=1)
                {
                        int mid=len>>1;
                        for(int j=0;j<n;j+=len)for(int i=0;i<mid;i++)
                        {
                                cp t=omega[n/len*i]*a[j+mid+i];
                                a[j+mid+i]=a[j+i]-t;
                                a[j+i]+=t;
                        }
                }
        }
        void fft(vector<cp>& a)
        {
                transform(a,omega);
        }
        void ifft(vector<cp>& a)
        {
                transform(a,iomega);
                for(int i=0;i<n;i++)a[i]/=n;
        }
vector<ll> s,a,b;
void mul()
{
        int n=1;
        int n1=(int)a.size(),n2=(int)b.size();
        while(n<n1+n2)n<<=1;
        vector<cp> tmp_a(n),tmp_b(n);
        for(int i=0;i<n1;i++)tmp_a[i]=cp(a[i],0);
        for(int i=0;i<n2;i++)tmp_b[i]=cp(b[i],0);
        init(n);
        fft(tmp_a);
        fft(tmp_b);
        for(int i=0;i<n;i++)tmp_a[i]*=tmp_b[i];
        ifft(tmp_a);
        s.resize(n);
        for(int i=0;i<n;i++)s[i]=round(tmp_a[i].real());
        while((int)s.size()>1 && s.back()==0)s.pop_back();
        return ;
}
int main()
{
        char c[maxn];
        bool flag=0;
        scanf("%s",c);
        int n=strlen(c);
        if(c[0]=='-')flag^=1;
        for(int i=0;i<n;i++)
        {
                if(c[i]!='-')a.push_back(c[i]-'0');
        }
        reverse(a.begin(),a.end());
        scanf("%s",c);
        if(c[0]=='-')flag^=1;
        n=strlen(c);
        for(int i=0;i<n;i++)
        {
                if(c[i]!='-')b.push_back(c[i]-'0');
        }
        reverse(b.begin(),b.end());
        vector<int> ans;
        mul();
        n=(int)s.size();
        int cur=0;
        for(int i=0;i<n;i++)
        {
                cur=cur/10+s[i];
                ans.push_back(cur%10);
        }
        cur/=10;
        if(cur)ans.push_back(cur);
        reverse(ans.begin(),ans.end());
        if(!flag || ((int)ans.size()==1 && ans[0]==0))
        {
                for(int i=0;i<(int)ans.size();i++)printf("%d",ans[i]);puts("");
        }
        else
        {
                putchar('-');
                for(int i=0;i<(int)ans.size();i++)printf("%d",ans[i]);puts("");
        }


        return 0;
}



Measured memory_bytes: 45704