akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(long long a, long long b, long long c, long long d, long long e, long long k){
	bool can = true;
	if (e-a>k) can = false;
	if (can) cout << "Yay!" << "\n";
	else cout << ":(" << "\n";
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);
    long long e;
    scanf("%lld",&e);
    long long k;
    scanf("%lld",&k);
    solve(a, b, c, d, e, k);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<pl,pl> pll;

ll N, M, Q, X, Y, Z, A, B, C, D, E, F, G;

ll arr[1000005];

vector<pl> AdjList[200005];

map<ll,ll> m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; ++i){
		cin >> arr[i];
	}
	for (int i = 1; i <= N; ++i){
		if (m.find(arr[i]) == m.end()){
			m[arr[i]] = 0;
		}
		m[arr[i]]++;
	}
	if (N%3!=0){
		for (int i = 1; i <= N; ++i){
			if (arr[i] != 0){
				cout << "No\n";
				return 0;
			}
		}
		cout << "Yes\n";
		return 0;
	}
	else{
		if (m.size() > 3){
			cout << "No\n";
			return 0;
		}
		if (m.size() == 3){
			ll x = 0;
			for (auto it : m){
				if (it.second != N/3){
					cout << "No\n";
					return 0;
				}
				x ^= it.first;
			}
			if (x != 0){
				cout << "No\n";
				return 0;
			}
		}
		else if (m.size() == 2){
			if (m.find(0) == m.end()){
				m[0] = 0;
			}
			if (m[0] != N/3){
				cout << "No\n";
				return 0;
			}
		}
		else if (m.size() == 1){
			if (m.find(0) == m.end()){
				m[0] = 0;
			}
			if (m[0] != N){
				cout << "No\n";
				return 0;
			}
		}
		cout << "Yes\n";
	}
}

Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 1010;
const int C = 5002;
int dp[N];
int n;
int a[N];
vector<int> g[N];

void dfs(int v) {
	dp[v] = -1;
	if (g[v].empty()) {
		dp[v] = 0;
		return;
	}
	int inner[2][C];
	for (int i = 0; i < C; i++)
		inner[0][i] = 0;
	for (int u : g[v]) {
		dfs(u);
		if (dp[u] == -1) {
			dp[v] = -1;
			return;
		}
		for (int i = 0; i < C; i++)
			inner[1][i] = -1;
		for (int x = 0; x < C; x++) {
			if (inner[0][x] == -1) continue;
			if (x + a[u] < C) {
				int w = inner[0][x] + dp[u];
				if (inner[1][x + a[u]] == -1 || inner[1][x + a[u]] > w)
					inner[1][x + a[u]] = w;
			}
			if (x + dp[u] < C) {
				int w = inner[0][x] + a[u];
				if (inner[1][x + dp[u]] == -1 || inner[1][x + dp[u]] > w)
					inner[1][x + dp[u]] = w;
			}
		}
		for (int x = 0; x < C; x++)
			inner[0][x] = inner[1][x];
	}
	for (int x = 0; x <= a[v]; x++) {
		if (inner[0][x] == -1) continue;
		if (dp[v] == -1 || dp[v] > inner[0][x])
			dp[v] = inner[0][x];
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int v;
		scanf("%d", &v);
		v--;
		g[v].push_back(i);
	}
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	dfs(0);
	for (int i = 0; i < n; i++)
		if (dp[i] == -1) {
			printf("IMPOSSIBLE\n");
			return 0;
		}
	printf("POSSIBLE\n");

	return 0;
}


Measured memory_bytes: 17024
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  int k; readV(k);

  string[] b;
  foreach (i; 0..s.length)
    foreach (j; 1..min(s.length-i, k)+1) {
      b ~= s[i..i+j];
      b = b.sort().uniq.array;
      b = b.take(k);
    }

  writeln(b.back);
}


Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int cnt = 0; //今までみつかった数
    for(int i = min(A,B); i >= 1; i--)
    {
        if(A % i == 0 && B % i == 0) {
            cnt++;
            if(cnt == K) {
                cout << i << endl;
                return 0;
            }
        }

    }
}

Measured memory_bytes: 256
N = int(input())
A = [int(s) for s in input().split()]
ans1 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 is 0:
        d = max(0, 1 - s)
        s += d
        ans1 += d
    else:
        d = max(0, 1 + s)
        s -= d
        ans1 += d
ans2 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 is 1:
        d = max(0, 1 - s)
        s += d
        ans2 += d
    else:
        d = max(0, 1 + s)
        s -= d
        ans2 += d
print(min(ans1, ans2))


Measured memory_bytes: 14468
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define rep(i,n,b) for(int i=0;i<n;i=i+b)
#define ld long double 
using namespace std;
int main()
{
    int n,d;
    int c=0;
    cin >> n >> d;
    while(n--)
    {
        double x,y;
        cin >> x >> y;
        double ans=sqrt((x*x)+(y*y));
        if(ans<=d)
        {
            c++;
        }
    }
    cout << c;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7 , mz = 1e9+7;
struct node{
    int l,r;
    node(){}
    void set(){
        scanf("%d%d",&l,&r);
    }
    bool operator < (const node& rhs){
        return l == rhs.l ? r < rhs.r : l < rhs.l;
    }
}a[N];
int nt[N];

int main(){
    int n,m;
    cin>>n>>m;
    nt[0] = 1;
    for(int i = 1 ; i <= m ; i++){
        a[i].set();
        nt[i] = i+1;
    }
    int&& z = m+1;
    nt[z] = z;
    sort(a+1,a+m+1);
    int ans = 0 , left = m;
    while( left  ){
        int y = 0;
        ans++;
        int l = a[nt[y]].l , r = a[nt[y]].r;
        left--;
        nt[0] = nt[nt[0]];
        //printf("out y = %d , nt[y] = %d , l = %d , r = %d\n",y,nt[y],l,r);
        while( nt[y] < z && a[ nt[y] ].l < r ){
            //printf("y = %d , nt[y] = %d , l = %d , r = %d\n",y,nt[y],l,r);
            //printf(" nt[y] . l = %d , r = %d\n" , a[ nt[y] ].l,a[ nt[y] ].r);
            if( a[ nt[y] ].r > l ){
                l = a[ nt[y] ].l;
                r = min( r , a[nt[y]].r );
                nt[y] = nt[nt[y]];
                left--;
            }else{
                y = nt[y];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
#define elif else if
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector <int>;
using vvi = vector <vi>;

signed main(){
	int x, y;
	cin >> x >> y;

	int cnt = 1;
	while(x * 2 <= y){
		x *= 2;
		cnt++;
	}

	cout << cnt << endl;




}


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





int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T; 
    cin >> A >> B;
    cin >> U;
    if (T.compare(U)){
        cout << A -1 << " " << B << endl;
    }
    else{
        cout << A << " " << B-1 << endl;        
    }
    return 0;
}

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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);

    int ans = 0;
    int num_1 = 0;
    int num_2 = 0;
    rep(i, m) {
        cin >> a[i];
        if (a[i] < x)
            num_1++;
        else
            num_2++;
    }

    ans = min(num_1, num_2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  fin(N*(N-1)/2);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<string.h>
using namespace std;
#define LL long long int
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI pair<int,int>
#define mem(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(v) (int)sizeof(v)
const int inf=0x3f3f3f3f;
const int mod=10007;
const int M=20;
using namespace std;
#define N 100005
int a[N];
int main()
{
    int n,t,ans=0;
    cin>>n;
    rep(i,1,n+1){
        scanf("%d",&t);
        a[i]=t;
        if(a[t]==i){
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1'000'000'007;
// constexpr i64 MOD = 998'244'353;
using m64 = modint<MOD>;

m64 modpow(m64 x, i64 n) {
    m64 res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

void solve() {
    i64 n;
    cin >> n;

    vector<p64> ab(n);
    map<p64, i64> cnt;
    i64 ans0 = 0;
    for (auto& [ a, b ] : ab) {
        cin >> a >> b;
        if (a == 0 && b == 0) {
            ans0++;
            continue;
        }

        if (b == 0) {
            a = 1;
        } else {
            i64 g = gcd(a, b);
            a /= g, b /= g;
            if (b < 0) a *= -1, b *= -1;
        }
        cnt[{ a, b }]++;
    }

    set<p64> use;
    use.emplace(0, 1);
    use.emplace(1, 0);
    m64 ans1 = modpow(2, cnt[{ 0, 1 }]) + modpow(2, cnt[{ 1, 0 }]) - 1;
    for (auto& [ a, b ] : ab) {
        if (use.find({ a, b }) != use.end()) continue;
        use.emplace(a, b);
        i64 na = -b, nb = a;
        if (nb < 0) na *= -1, nb *= -1;
        ans1 *= modpow(2, cnt[{ a, b }]) + modpow(2, cnt[{ na, nb }]) - 1;
        use.emplace(na, nb);
    }
    cout << ans1 - 1 + ans0 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

int main()
{
   int n;
   cin>>n;
   unordered_map<ll,ll>m;
   for(int i=0;i<n;i++)
   {
   	ll a;
   	cin>>a;
   	m[a]++;
   }
   ll ans=0;
   for(auto i:m)
   {
   	if(i.first!=i.second)
   		{
               if(i.second>i.first)
               ans+=(i.second-i.first);
               else
               ans+=i.second;
           }
   }
   cout<<ans;
  


   
}

Measured memory_bytes: 4260
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int H, W, h, w;
    io.read(H, W, h, w);
    cout << H * W - (h * W + w * H - h * w);
    return 0;
}

Measured memory_bytes: 256
def fer(n, r, p):
    # calculate n_C_k mod p
    # a,pが互いに素のとき a ^ (p-2) = a ^ -1 (mod p)
    x, y = 1, 1
    for i in range(r):
        x *= (n - i)
        x %= p
        y *= (i + 1)
        y %= p
    # x -> n * (n-1) * ... * (n-r+1)
    # y -> 1 * 2 * ... * r
    return x * pow(y, p - 2, p) % p


def main():
    x, y = map(int, input().split())

    if x/y < 1/2 or x/y > 2 or (x + y) % 3 != 0:
        print(0)
        exit()

    n, m = (2*y-x)//3, (2*x-y)//3
    ans = fer(n+m, n, 10 ** 9 + 7)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(void)
{
  // ll n; cin >> n;
   ll k, a, b; cin >> k >> a >> b;
  // string s; cin >> s;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  // ll ans = 0;
  bool ok = false;
  ll c = (a / k);
  
  if( a % k == 0 || (c+1) * k <= b) ok = true;
  // cout << ans << endl;
  cout << (ok?"OK":"NG") << endl;
}


Measured memory_bytes: 3636
#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 d; cin >> d;
    vector<int> clis(26);
    vector<vector<int>> slis(d, vector<int>(26));
    REP(i, 0, 26){cin >> clis[i];}
    REP(i, 0, d){
        int idx, max = -1;
        REP(l, 0, 26){
            cin >> slis[i][l];
            if(chmax(max, slis[i][l])){
                idx = l+1;
            }
        }
        cout << idx << endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int c[14];
vector<int> res;
bool dfs(int left, int sum)
{
	if (left == 0 && sum == 0)
		return true;

	for (int i = 1; i <= 13; ++i)
	{
		if (c[i] && sum % i == 0)
		{
			--c[i];
			if (dfs(left - 1, sum - i))
			{
				res.push_back(i);
				return true;
			}
			++c[i];
		}
	}

	return false;
}
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		CLEAR(c, 0);
		res.clear();

		rep (i, n)
		{
			int t;
			scanf("%d", &t);
			++c[t];
		}

		int s = 0;
		for (int i = 1; i <= 13; ++i)
			s += i * c[i];
		if (dfs(n, s))
		{
			for (int i = 0; i < res.size(); ++i)
				printf("%d%c", res[i], i + 1 == res.size() ? '\n' : ' ');
		}
		else
			puts("No");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm> 
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 15;
int n, a, b, c, d, ans, dp[N][N], C[N][N], dp2[N][N], rev[N], fact[N];

// dp2[i people][j groups]


inline void add(int &a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	if(a < 0)
		a += mod;
}

inline int mt(int a, int b) {
	return ((ll)a * b) % mod;
}

inline void precalc() {
	C[0][0] = 1;
	for(int i = 1; i < N; ++i)
		for(int j = 0; j <= i; ++j)
			add(C[i][j], C[i-1][j] + (j ? C[i-1][j-1] : 0));
	rev[1] = 1;
	for(int i = 2; i < N; ++i)
		add(rev[i], -mt(mod / i, rev[mod % i]));
	for(int i = 1; i < N; ++i) {
		dp2[i][1] = 1;
		for(int j = 2; j * i < N; ++j)
			dp2[i][j] = mt(mt(dp2[i][j-1], C[i * j][i]), rev[j]);
	}
}

main() {
	precalc();
	scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
	// dp2[i size][j groups] - number of ways to distribute i people in j groups
	// dp[i people][size >= j]
	dp[0][b+1] = 1;
	for(int j = b; j >= a; --j)
		for(int i = n; i >= 0; --i) {
			dp[i][j] = dp[i][j+1];
			for(int l = c; l <= d && j * l <= i; ++l)
				add(dp[i][j], mt(dp2[j][l], mt(C[i][j * l], dp[i - j * l][j+1])));
		}
	printf("%d\n", dp[n][a]);
    return 0;
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
int main()
{
    ll n,w;
    cin>>n>>w;
    vector <int> weight(n),val(n);
    ll total = 0;
    for(int i=0;i<n;i++)
        cin>>weight[i]>>val[i],total += val[i];
    vector <ll> dp(total+1,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=total;j>=val[i]&&j>=0;j--)
            dp[j] = min(dp[j],dp[j-val[i]]+weight[i]);
    }
    int ans = 0;
    for(int i=0;i<=total;i++)
    {
        if(dp[i] <= w)
            ans = max(ans,i);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	int sum = 0;
	FOR(i, 1, n + 1)
	{
		sum += i;
		if (sum >= n)
		{
			int t = n;
			for (int j = i; t > 0; j--)
			{
				if (t >= j)
				{
					cout << j << endl;
					t -= j;
				}
			}
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split(" ")))

lr = 0
ll = sum(a)
index = 0

while lr + a[index] < ll - a[index]:
    lr = lr + a[index]
    ll = ll - a[index]
    index += 1

diff = min(ll - lr, lr + 2 * a[index] - ll)
print(diff)


Measured memory_bytes: 26396
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
long long a,b,c,d;
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
if (abs(c-a)<=d || abs (b-a)<=d && abs (c-b)<=d)
printf("Yes");
else
printf("No");
}

Measured memory_bytes: 1708
module Main where

import Control.Applicative
import Text.Printf

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine


main :: IO ()
main = do
  { ss <- getInt
  ; let (q, s) = divMod ss 60
  ; let (h, m) = divMod q 60
  ; putStrLn (show h ++ ":" ++ show m ++ ":" ++ show s)
  }



Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fi first
#define se second
 
const ll MOD = 1000000007;
const string RGB = "RGB"; 

int main() {
   int n, a, b; scanf("%d%d%d", &n, &a, &b);
   printf("%d", min(a * n, b));
   return 0;
}

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


Measured memory_bytes: 68128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), l = sc.nextInt();

        int[] ar = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            ar[i] = i + l;
            sum += ar[i];
        }
        int d = 100 * 100 * 100, ans = -1;
        for (int i = 0; i < n; i++) if (d > Math.abs(sum - (sum - ar[i]))) {
            d = Math.abs(sum - (sum - ar[i]));
            ans = sum - ar[i];
        }
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <functional>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int n;
	int x;
	int s;
	int itr;
	int cnt = 0;
	int ans = 0;
	cin>> n;
	vector<int> a;
	REP(i, n){
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());


	s = *a.begin();
	//cout << "a" << endl;
	while (1){
		//itr = a.begin();
		itr = upper_bound(a.begin(), a.end(), s) - a.begin();
		//cout << itr << endl;
		if (s == itr - cnt){

		}
		else if (s > itr - cnt){
			ans = ans + itr - cnt;
		}
		else{
			ans = ans + itr - cnt - s;
		}
		cnt = itr;
		//cout << s << endl;
		//int t = s;
		if (cnt == n){
			break;
		}
		s = *(upper_bound(a.begin(), a.end(), s));
		
		
	}
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 892
# https://atcoder.jp/contests/abc161/tasks/abc161_e


def main():
    n, k, c = map(int, input().split(" "))
    s = [s for s in input()]
    l = [0] * n
    r = [0] * n
    day = 1
    i = 0
    while day <= k and i < n:
        if s[i] == "o":
            l[i] = day
            day += 1
            i += c + 1
        else:
            i += 1
    i = n - 1
    day = k
    while day > 0 and i >= 0:
        if s[i] == "o":
            r[i] = day
            day -= 1
            i -= c + 1
        else:
            i -= 1
    for i in range(n):
        if l[i] > 0 and l[i] == r[i]:
            print(i + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21980
//
//  main.cpp
//  ABC093
//
//  Created by hiroaki on 2019/03/18.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

//~~A~~
/*int main(){
    string s;
    cin >> s;
    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}*/

//~~B~~
/*int main(){
    int a,b,k;
    cin>>a>>b>>k;
    
    if (b-a+1>2*k) {
        for (int i=0; i<k; i++) {
            cout<<a+i<<endl;
        }
        for (int i=k; i>0; i--) {
            cout<<b-i+1<<endl;
        }
    }else{
        for (int i=0; i<b-a+1; i++) {
            cout<<a+i<<endl;
        }
    }
    return 0;
}*/

//~~C~~
int main(){
    int a,b,c;
    cin >>a>>b>>c;
    vector<int> v ={a,b,c};
    int max = *max_element(v.begin(), v.end());
    if ((3*max-(a+b+c))%2==0) {
        cout<<(3*max-(a+b+c))/2<<endl;
    }else{
        cout<<(3*(max+1)-(a+b+c))/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX_V 51
bool used[MAX_V];
int s[MAX_V][MAX_V];
int n,m;
void dfs(int v){
  used[v] = true;
  rep(i,n){
    if(!used[i] && s[v][i]) dfs(i);
  }
  return ;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a[MAX_V*MAX_V],b[MAX_V*MAX_V];
  cin >> n >> m;
  rep(i,n) rep(j,n) s[i][j]=false;
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    s[a[i]][b[i]] = true;
    s[b[i]][a[i]] = true;
  }
  int ans = 0;
  rep(i,m){
    s[a[i]][b[i]] = false;
    s[b[i]][a[i]] = false;
    rep(i,n) used[i] = false;
    dfs(0);
    bool flag = true;
    rep(i,n) if(used[i]==false){flag = false; break;}
    if(!flag) ans++;
    s[a[i]][b[i]] = true;
    s[b[i]][a[i]] = true;

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


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

int main() {
  int64_t a, b ,k;
  cin >> a >> b >> k;
  for (int64_t i=a ; i<=b ; i++){
    if ( i-a<=k-1 || b-i<=k-1){
      cout << i <<endl;
    }
  }
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];
    bool ok = true;
    for(int i=0;i<n;i++){
        if(vec[i]%2==0){
            if(vec[i]%3!=0 && vec[i]%5!=0) ok = false;
        }
    }
    if(ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        List<int> A = new List<int>();

        int maxValue = 1;
        int secondMaxValue = 0;
        int cntMaxValue = 0;
        int currentValue;

        for(int i = 0; i < N; i++) {
            currentValue = int.Parse(Console.ReadLine());
            A.Add(currentValue);

            if(maxValue == currentValue) { 
                cntMaxValue++;
            } else if(maxValue < currentValue) {
                secondMaxValue = maxValue;
                maxValue = currentValue;
                cntMaxValue = 1;
            } else if(secondMaxValue < currentValue) {
                secondMaxValue = currentValue;
            }
        }

        for(int i = 0; i < N; i++) {
        
            if(cntMaxValue > 1) {
                Console.WriteLine(maxValue);
                continue;
            }
            
            if (A[i] == maxValue) {
                Console.WriteLine(secondMaxValue);
            }
            else {
                Console.WriteLine(maxValue);
            }

        }
    }
}

Measured memory_bytes: 18580
#include <iostream>

using namespace std;

int main() {
    int a,b,c,d;
    int l, r;
    cin >> a >> b >> c >> d;

    l = a + b;
    r = c + d;
    if (l == r) {
        cout << "Balanced" << endl;
    }
    else if (l > r) {
        cout << "Left" << endl;
    }
    else if (l < r) {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var m = parseInt(input[0].split(" ")[1]);
  var ans = Math.pow(2,m)*(1900*m+100*(n-m));
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807


int main()
{
ll n,k;
cin >> n >> k ;
vector<ll> v;
rep(i,n){
  ll r=n/(i+1);
  ll s=n/r;
  v.push_back(s-i);
  i=s-1;
}
ll ans[v.size()];
rep(i,v.size()){
  ans[i]=v[i];
}
ll sum[v.size()];
rep(i,k){
  rep(j,v.size()){
    if(j==0)sum[0]=ans[0];
    else {sum[j]=ans[j]+sum[j-1];sum[j]%=mo;}
  }
  rep(j,v.size()){
    ans[j]=v[j]*sum[v.size()-j-1];
    ans[j]%=mo;
  }
}

cout << sum[v.size()-1] << endl;
return 0;
}


Measured memory_bytes: 1912
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string ss = s;
    int l = s.length();

    if (l == 26) {
        if (!std::next_permutation(s.begin(), s.end())) {
            cout << "-1";
        } else {
            for (int i = 0; i < 26; i++) {
                cout << s[i];
                if (s[i] != ss[i]) return 0;
            }
        }
    } else {
        for (char c = 'a';; c++) {
            bool ok = true;
            for (char cc : s) {
                if (cc == c) ok = false;
            }
            if (ok) {
                cout << s + c;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
using ll=long long;
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main(){
  int n;
  ll ans=0;
  cin>>n;
  vec A(n);
  vec w;
  int c[MAX_N];
  vec d;
  for(int i=0;i<n;i++){
    cin>>A[i];
    if(A[i]>MAX_N){
      ans++;
    }
    else{
      c[A[i]]++;
    }
  }
  for(int i=0;i<n;i++){
    if(A[i]<=MAX_N&&c[A[i]]<A[i]){
      d.push_back(A[i]);
      ans++;
    }
  }
  sort(d.begin(),d.end());
  int t[MAX_N];
  for(int i=0;i<n;i++){
    if(A[i]<=MAX_N&&t[A[i]]!=-1234&&!binary_search(d.begin(),d.end(),A[i])){
      w.push_back(A[i]);
      t[A[i]]=-1234;
    }
  }
  for(int i=0;i<w.size();i++){
    ans+=c[w[i]]-w[i];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int N;
ll K;
vector<int> A, F;

/*
bool isOK(ll mid){
    ll count = 0;
    rep(i,N){
        count += max(0ll, A[i] - mid/F[i]);
    }
    if (count <= K) return true;
    else return false;
}

ll binary_search(){
    ll ng = -1;
    ll ok = 1e12;

    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;

        if(isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}
*/
int main(){
    /*
    int N;
    ll K;
    */
    cin >> N >> K;
    
    //vector<int> A(N), F(N);
    A.assign(N,0), F.assign(N,0);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll ng = -1;
    ll ok = 1e12;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;
        ll count = 0;
        rep(i,N){
            count += max(0ll, A[i] - mid/F[i]);
        }
        if(K >= count){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout << ok << endl;
}

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

// clang-format off
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

#define rep(i, n) for (int i = 0; i < (int)(n); ++(i))
#define reps(i, n) for (int i = 1; i <= (int)(n); ++(i))
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --(i))
#define rreps(i, n) for (int i = (int)(n); i > 0; --(i))

#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)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

using int32 = int;
using int64 = long long;

constexpr int mod     = 1e9 + 7;
constexpr int32 inf   = 1001001001;
constexpr int64 infll = 1001001001001001001ll;
constexpr int dx[]    = {0, -1, 1, 0, -1, 1, -1, 1},
              dy[]    = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; 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.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

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

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

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(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 A = input(), B = input();

  if (B % A == 0) cout << A + B << endl;
  else cout << B - A << endl;
}

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


Measured memory_bytes: 256
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	usage := []int{0, 2, 5, 5, 4, 5, 6, 3, 7, 6}
	var n, m int
	fmt.Sscan(getNextLine(scanner), &n, &m)

	aaa := getIntList(scanner)
	sort.Sort(sort.IntSlice(aaa))
	dp := make([]int, n+1)
	for i := 1; i <= n; i++ {
		dp[i] = -1
	}
	for i := 0; i <= n; i++ {
		if dp[i] == -1 {
			continue
		}
		for j := 0; j < m; j++ {
			if usage[aaa[j]]+i > n {
				continue
			}
			if dp[i]+1 > dp[usage[aaa[j]]+i] {
				dp[usage[aaa[j]]+i] = dp[i] + 1
			}
		}
	}

	matches := n
	ans := ""
	for matches > 0 {
		for i := m - 1; i >= 0; i-- {
			if matches-usage[aaa[i]] < 0 {
				continue
			}
			if dp[matches]-1 == dp[matches-usage[aaa[i]]] {
				ans += fmt.Sprintf("%d", aaa[i])
				matches -= usage[aaa[i]]
				break
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
int p[30];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	p[n]=-999;
	for(int i=1;i<n-1;i++)
	{
		int s[3]={p[i-1],p[i],p[i+1]};
		sort(s,s+3);
		if(s[1]==p[i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def f(a, D):
    N = len(D)
    p = []
    for i in range(N):
        if D[a][i] == 1:
            p.append(i)
    return p


def wfs(e, D):
    N = len(D)
    a, b = e[0], e[1]

    p = f(a, D)
    used = [a]
    while len(p) > 0:
        x = p.pop(0)
        used.append(x)

        if x == b:
            return True

        q = f(x, D)
        for j in q:
            if j in used:
                continue
            p.append(j)

    return False


def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    G = []
    for _ in range(M):
        a, b = map(int, input().split())
        G.append((a-1, b-1))

    ans = 0
    for i in range(M):
        D = [[0 for _ in range(N)] for _ in range(N)]
        for j in range(M):
            if j == i:
                continue

            a, b = G[j][0], G[j][1]
            D[a][b] = 1
            D[b][a] = 1

        if not wfs(G[i], D):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
def lake(x,y):
    l[x][y] = "."
    for i in range(2):
        xi = x + dx[i]
        yi = y + dy[i]
        if 0 <= xi < n and 0 <= yi < m and l[xi][yi] == "#":
            lake(xi,yi)
            break


n,m = map(int, input().split())
l = [list(input()) for _ in range(n)]
l[0][0]=="."
dx = [1,0]
dy = [0,1]
lake(0,0)
for i in range(n):
    for j in range(m):
        if l[i][j] == "#":
            print("Impossible")
            exit()

print("Possible")


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int compare(const void* a, const void* b){
  if(*(long long*)a > *(long long*)b) return -1;
  if(*(long long*)a < *(long long*)b) return 1;
  return 0;
}

int main(){
  int N, A, B;
  scanf("%d%d%d", &N ,&A ,&B);
  
  long long v[N];
  for(int i = 0; i < N; i++) scanf("%lld", v + i);
  qsort(v, N, sizeof(long long), compare);
  
  long double average = 0;
  for(int i = 0; i < A; i++) average += v[i];
  average /= A;
  
  printf("%.7Lf\n", average);
  
  int count = 0;
  for(int i = 0; i < N; i++){
    if(v[i] == v[A - 1]) count++;
  }
  
  long long binom[51][51];
  for(int i = 0; i <= 50; i++){
    for(int j = 0; j <= 50; j++){
      if(j == 0 || j == i){
        binom[i][j] = 1;
      }else{
        binom[i][j] = 0;
      }
    }
  }
  
  for(int i = 1; i <= 50; i++){
    for(int j = 1; j <= i; j++){
      binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
    }
  }
  
  if(v[0] == v[A - 1]){
    long long c = 0;
    for(int i = A; i <= B; i++){
      c += binom[count][i];
    }
    
    printf("%lld\n", c);
  }else{
    int cnt = 0;
    for(int i = 0; i < A; i++){
      if(v[i] == v[A - 1]) cnt++;
    }
    
    long long c = binom[count][cnt];
    
    printf("%lld\n", c);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second

signed main() {
	ll n;
	cin>>n;
	vector<ll> dp(n+1);
	vector<ll> a(n);
	rep(i,n) cin>>a[i];
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
	FOR(i,2,n){
		dp[i] = min(dp[i-1] + abs(a[i-1] - a[i]), dp[i-2] + abs(a[i-2] - a[i]));
		// cout<<dp[i]<<endl;
	}
	cout<<dp[n-1];
	
	
}

Measured memory_bytes: 4804
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;
#define MOD 1000000007LL

int n,a[100005];
int b[100005];

int main() {

	scanf("%d ",&n);
	FORI(0,n){
		scanf("%d ",&a[i]);
	}
	bool flg=true;
	FORI(0,n){
		b[a[i]]++;
	}
	if(n%2){
		FORI(0,n){
			if(i==0){
				if(b[0]!=1)
					flg=false;
			}
			else if(i%2==0){
				if(b[i]!=2)
					flg=false;
			}
			else if(i%2==1){
				if(b[i]!=0)
					flg=false;
			}		
		}
	}
	else{
		FORI(0,n){
			if(i%2==0){
				if(b[i]!=0)
					flg=false;
			}
			else if(i%2==1){
				if(b[i]!=2)
					flg=false;
			}		
		}
	}
	if(!flg){
		cout << "0"<< endl;
		return 0;
	}
	ll ans=1;
	if(n%2){
		FORI(0,n/2){
			ans=ans*2%MOD;
		}
	}
	else{
		FORI(0,n/2){
			ans=ans*2%MOD;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 1024
@$_=$_ for@p=0..<>;map{unshift@a,$#p*~-$#p/2-$%;($A,$B)=@p[glob];@$B>@$A or$A^=$B^=$A^=$B;$%+=$B-$A&&@$B*map$p[$$B[@$B]=$_]=$B,@$A}reverse<>;print"@a"

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

int main() {
  int n, k;
  string s;
  cin >> n;
  cin >> s;
  cin >> k;
  for(int i=0; i<n; i++){
    if(s.at(i) != s.at(k-1)){
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long int
#include<bits/stdc++.h>
#include<deque>
#define pb push_back
#define pf push_front
int main(){
  string s;
  cin>>s;
  deque<char>d;
  for(int i=0;i<s.size();i++)
    d.pb(s[i]);
  int q;
  cin>>q;
  bool dec=false;
  while(q--){
    int p;
    cin>>p;
    if(p==1)
      dec=dec^(true);
    else{
      int t;cin>>t;
      char c;cin>>c;
      if(dec){
        if(t==1)
          d.pb(c);
        else
          d.pf(c);
      }
      else{
        if(t==1)
          d.pf(c);
        else
          d.pb(c);
      }
    }
  }
  string ans;
  for(auto &x:d){
    ans+=x;
  }
  if(dec)
    reverse(ans.begin(),ans.end());
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
int dp[22][(1<<22)];
int solve(vector<vector<int>> &compat,int i,int womenSubset,int N){
    if(i==N+1){
        if(womenSubset == 0)
            return 1;
        return 0;
        }
        if(dp[i][womenSubset] != -1){return dp[i][womenSubset];}
        long ans=0;
        for(int women=0;women<N;women++){
            int available = womenSubset & (1<<women) ? 1 : 0;
            if(available && compat[i][women+1]){
                ans = (ans + solve(compat, i+1, womenSubset^(1<<women), N))%1000000007;
            }

        }
        return dp[i][womenSubset] = ans;
}
int32_t main() {
    cin>>n;
    int a;
    vector<vector<int>> compat(n+1,vector<int>(n+1));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>compat[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(compat, 1, (1<<n)-1, n);
}


Measured memory_bytes: 724432