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

int main() {

    ll N, K, S;
    cin >> N >> K >> S;

    for (int i = 0; i < N; i++) {
        if (i < K) {
            cout << S;
        }
        else {
            if (S == 1000000000) {
                cout << 1;
            }
            else {
                cout << 1000000000;
            }
        }
        cout << " ";
    }
    cout << endl;

    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, K;
ll A[200000];

int main() {
    cin >> N >> K;
    REP(i, N) A[IN()]++;
    sort(A, A + 200000, greater<ll>());
    ll ans = N;
    REP(i, K) ans -= A[i];
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("B.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,x,q=0;
    cin >> a >> b >> c >> x;
    rep(i, 0, a+1){
        rep(j, 0, b+1){
            rep(k, 0, c+1){
                if(500*i+100*j+50*k==x){
                    // cout << i << " " << j << " "<< k << endl;
                    q++;
                }
            }
        }
    }
    cout << q << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m,k;cin>>n>>m>>k;
    //char a[n+1][n+1];
    string s[n+1];
    for (int i = 0; i < n; ++i)
    {
        cin>>s[i];
    }
	int cnt = 0;
	int n1  = (1<<n);
	int m1 = (1<<m);
	ll ans = 0;
	for (int is = 0; is < n1; ++is)
	{   cnt = 0;
		for (int js = 0; js < m1; ++js)
		{
			cnt = 0;
			for (int i = 0; i < n; ++i)
			{
				for (int j = 0; j < m; ++j)
				{
					if((is>>i)&1 == 1) continue;
					else if((js>>j)&1 == 1) continue;
					else if(s[i][j] == '#'){
						cnt++;
					}

				}
			}
			if(cnt == k) ans++;
		}
	}
	cout<<ans<<"\n";

}



Measured memory_bytes: 3628
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
#define LEAD (lead && !i)
#define LIM (lim && i == buc[pos])
#define ABS(x) (x) < 0 ? (-x) : (x)
#define RG register
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 300000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int INF = 0x3f3f3f3f;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

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

int main() {
    // std::ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        a[i] = i * (n + 1);
        b[i] = (n - i + 1) * (n + 1);
    }
    for (int i = 1; i <= n; i++) {
        int p;
        cin >> p;
        a[p] -= (n - i + 1);
    }
    for (int i = 1; i <= n; i++) printf("%d%c", a[i], i == n ? '\n' : ' ');
    for (int i = 1; i <= n; i++) printf("%d%c", b[i], i == n ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ft(i,l,r) for(register int i=l;i<=r;i++)
#define fd(i,r,l) for(register int i=r;i>=l;i--)
using namespace std;
int n,m,a[2333],s,ans;
int main()
{
    cin>>n>>m;
    ft(i,1,n)
    {
    	scanf("%d",&a[i]);
    	s+=a[i];
    }
    ft(i,1,n)
      if(a[i]*4*m>=s) ans++;
    if(ans>=m) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int L, R, D; cin >> L >> R >> D;
	print(R / D - (L - 1) / D);
}

Measured memory_bytes: 3612
#include <cmath>
#include <cassert>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;

class IntervalSet {
    map<long long, int> repr;
public:
    void add(long long lb, long long ub) {
        repr[lb]++;
        repr[ub+1]--;
    }
    long long count();
};

long long IntervalSet::count() {
    long long ret = 0, prev;
    int count = 0;
    for (auto &p : repr) {
        if (p.second > 0) {
            if (count == 0) prev = p.first;
            count += p.second;
        }
        if (p.second < 0) {
            count += p.second;
            if (count == 0) ret += p.first - prev;
        }
    }
    return ret;
}

int gcd(int a, int b) {
    while (b > 0) { int t = b; b = a % b; a = t; }
    return a;
}

int main() {
    int N, X, D; cin >> N >> X >> D;
    if (D == 0) { cout << (X == 0 ? 1 : N+1) << endl; return 0; }
    if (D < 0) D = -D, X = -X;
    int g = gcd(abs(D), abs(X));
    X /= g; D /= g;

    long long ans = 0;
    for (int r = 0; r < D; r++) {
        IntervalSet intervals;
        for (long long k = r; k <= N; k += D) {
            long long lb = k * X + k * (k-1) / 2 * D,
                ub = k * X + (N * k - k * (k+1) / 2) * D;
            intervals.add((lb - (lb % D + D) % D) / D,
                          (ub - (ub % D + D) % D) / D);
        }
        ans += intervals.count();
    }
    cout << ans << endl;
}


Measured memory_bytes: 25216
a, b, c = gets.chomp.split(" ").map(&:to_i);
if (a >= 1 && a <= 100) && (b >= 1 && b <= 100) && (c >= 1 && c <= 100) then
  tasks = [a, b, c]
  tasks.sort!
  costs = (tasks[1] - tasks[0]) + (tasks[2] - tasks[1])
  puts costs
end


Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[100][11],t[100][11];
    int n,m,a=0,i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%s",s[i]);
    scanf("%d",&m);
    for(i=0;i<m;i++)scanf("%s",t[i]);
    for(i=0;i<n;i++){
        k=0;
        for(j=0;j<n;j++)if(strcmp(s[i],s[j])==0)k++;
        for(j=0;j<m;j++)if(strcmp(s[i],t[j])==0)k--;
        if(k>a)a=k;
    }
    printf("%d",a);
}

Measured memory_bytes: 128
import java.util.Scanner;

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

        s += s;

        if (s.contains(p)) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 26180
#include <iostream>

using namespace std;
using ll = long long;

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

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  rep(h, 1, 3501) {
    rep(n, 1, 3501) {
      if (4*h*n/N-n-h == 0)
        continue;
      int w = h * n / (4*h*n/N-n-h);
      if (w <= 0)
        continue;
      if (4*h*n*w == (n*w+h*w+h*n)*N) {
        out(h << " " << n << " " << w);
        return 0;
      }
    }
  }


  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    vector<vector<ll>> cnt(M);
    rep(i, N) {
        cnt[X[i] % M].push_back(X[i]);
    }
    ll ans = 0;
    ans += cnt[0].size() / 2;
    if (M % 2 == 0) ans += cnt[M / 2].size() / 2;

    rep2(i, 1, (M + 1) / 2) {
        auto T = cnt[i];
        auto S = cnt[M - i];
        if (S.size() > T.size()) {
            swap(T, S);
        }
        ll more = T.size() - S.size();
        ans += S.size();

        map<ll, ll> cnt2;
        for (ll t: T) {
            cnt2[t]++;
        }
        ll sum = 0;
        for (P p: cnt2) {
            sum += p.second / 2;
        }
        ans += min(more / 2, sum);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	ll H, W;
	cin>>H>>W;
	ll sa = INF * INF;
	FOR(i, 1, H) {
		ll m1 = i * W;
		ll m2, m3;
		ll smax, smin;
		if((H - i) % 2 == 0) m2 = m3 = (H - i) / 2 * W;
		else {
			m2 = ((H - i) / 2 + 1) * W;
			m3 = (H - i) / 2 * W;
		}
		smax = max(max(m1, m2), m3);
		smin = min(min(m1, m2), m3);
		sa = min(sa, smax - smin);
		if(W % 2 == 0) m2 = m3 = W / 2 * (H - i);
		else {
			m2 = (W / 2 + 1) * (H - i);
			m3 = W / 2 * (H - i);
		}
		smax = max(max(m1, m2), m3);
		smin = min(min(m1, m2), m3);
		sa = min(sa, smax - smin);
	}
	swap(H, W);
	FOR(i, 1, H) {
		ll m1 = i * W;
		ll m2, m3;
		ll smax, smin;
		if((H - i) % 2 == 0) m2 = m3 = (H - i) / 2 * W;
		else {
			m2 = ((H - i) / 2 + 1) * W;
			m3 = (H - i) / 2 * W;
		}
		smax = max(max(m1, m2), m3);
		smin = min(min(m1, m2), m3);
		sa = min(sa, smax - smin);
		if(W % 2 == 0) m2 = m3 = W / 2 * (H - i);
		else {
			m2 = (W / 2 + 1) * (H - i);
			m3 = W / 2 * (H - i);
		}
		smax = max(max(m1, m2), m3);
		smin = min(min(m1, m2), m3);
		sa = min(sa, smax - smin);
	}
	cout<<sa<<endl;
}


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

using namespace std;

long long x[100001], endx[100001];
long long w[100001];

int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
#endif

	long long n, l, t;
	cin >> n >> l >> t;
	for (long long i = 1; i <= n; ++i) {
		cin >> x[i] >> w[i];
		if (w[i] == 2) w[i] = -1;
		endx[i] = ((x[i] + t * w[i]) % l + l) % l;
	}

	sort(endx + 1, endx + n + 1);

	long long c = 1;
	for (long long i = 1; i <= n; ++i) {
		if (w[i] == 1) {
			if (t < l - x[i]) continue;
			c = (c + (t - (l - x[i])) / l) % n + 1;
		} else {
			if (t < x[i] + 1) continue;
			c = (c + n - (t - x[i] - 1) / l % n - 2) % n + 1;
		}
	}

	for (long long i = c; i <= n; ++i) cout << endx[i] << '\n';
	for (long long i = 1; i < c; ++i) cout << endx[i] << '\n';

	return 0;
}

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

public class Main {
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		sc.close();
		System.out.println(
				firstst(sx, sy, tx,ty)
				+ firstts(sx, sy, tx,ty)
				+ secondst(sx, sy, tx, ty)
				+ secondts(sx, sy, tx, ty));

	}
	
	private static String firstst(int sx, int sy, int tx, int ty){
		return repeat('U', ty - sy) + repeat('R', tx - sx);
	}
	
	private static String firstts(int sx, int sy, int tx, int ty){
		return repeat('D', ty - sy)+ repeat('L', tx - sx);
	}
	
	private static String secondst(int sx, int sy, int tx, int ty){
		return "L" + firstst(sx - 1, sy, tx, ty + 1) + "D";
	}
	
	private static String secondts(int sx, int sy, int tx, int ty){
		return "R" + firstts(sx, sy -1, tx + 1, ty) + "U";
	}
	
	private static String repeat(char c, int n){
		char[] chars = new char[n];
		Arrays.fill(chars, c);
		return new String(chars);
	}

}


Measured memory_bytes: 10188
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int G = 11;
const int N = 2010;
const int K = N;

int calc(int g, int num, int val[][N])
{
  int sum = 0;
  for(int i = 0; i < num; ++i){
    sum += val[g][i];
  }
  return sum + num * (num-1);
}

int main()
{
  int n,k;
  while(cin>>n>>k){
    if(n==0&&k==0)break;
    
    static int val[G][N];
    static int dp[G][K];
    static int num[G] = {0,};

    for(int i = 0; i < n; ++i){
      int v,g;
      cin >> v >> g;
      val[g][num[g]] = v;
      num[g]++;
    }

    for(int g = 0; g < G; ++g){
      sort(val[g],val[g]+num[g]);
      reverse(val[g],val[g]+num[g]);
    }

    for(int i = 0; i < G; ++i){
      for(int j = 0; j <= k; ++j){
        dp[i][j] = 0;
      }
    }

    for(int g = 1; g < G; ++g){
      for(int i = 0; i <= k; ++i){
        for(int l = 0; l <= k; ++l){
          if( i-l < 0 ) break;
          if( l > num[g] ) break;
          dp[g+1][i] = max(dp[g+1][i], dp[g][i-l] + calc(g,l,val) );
        }
      }
    }

    cout << dp[G][k] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100;

ll N,D,X,a[MAX_N];

int main(){
  cin>>N>>D>>X;
  for(ll i=0;i<N;i++)cin>>a[i];
  ll ans=0;
  for(ll i=0;i<N;i++){
    a[i];
    ans+=((D-1)/a[i])+1;
  }
  cout<<(ans+X)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
int N, K;
int V[120];

void solve() {

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}

	int ans = 0;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K - i; j++) {
			int tmp = 0;
			vector<int> minus;
			for (int m = 0; m < i; m++) {
				if (m >= N - j) break;
				tmp += V[m];
				if (V[m] < 0) minus.eb(V[m]);
			}
			for (int m = 0; m < j; m++) {
				if (N - 1 - m < i) break;
				tmp += V[N - 1 - m];
				if (V[N - 1 - m] < 0) minus.eb(V[N - 1 - m]);
			}
			sort(minus.begin(), minus.end(), greater<int>());
			for (int m = 0; m < K - (i + j); m++) {
				if (minus.empty()) break;
				tmp -= minus.back();
				minus.pop_back();
			}
			ans = max(ans, tmp);
		}
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second 

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf = 4e18;
int x,d,n;
map<int,vector<pii>>mp;
ll ans=0;
ll sum(int l,int r){
	return 1ll * (l+r) * (r-l+1) / 2;
}
int main(){
	cin >> n >> x  >> d;
	if (x == 0 && d == 0){
		cout << 1 << '\n';
		return 0;
	}
	if (d == 0){
		cout << n + 1 << '\n';
		return 0;
	}
	
	if (d<0){
		x = -x;
		d = -d;
	}
	
	for (int i=0;i<=n;i++){
		ll p = ( 1ll * i * x % d + d ) % d;
		ll l = 1ll * i * x + sum(0,i-1) * d;
		ll r = 1ll * i * x + sum(n-i,n-1) * d;
		mp[p].push_back({l,r});
	}
	
	for (auto i:mp){
		ll r = -inf;
		vector<pii> q = i.second;
		sort(q.begin(),q.end());
		for (int j = 0;j < q.size(); j++){
			if (q[j].x <= r){
				if (q[j].y >= r){
					ans += (q[j].y - r) / d;
					r = q[j].y;
				}
			}else{
				r = q[j].y;
				ans += (q[j].y - q[j].x) / d + 1;
			}
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 22144
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5+5, LG = 19, MOD = 1e9+7;
const int SQ =320;
const long double EPS = 1e-7;
int n;
ll a[200005];
ll sum[200005][2];
ll dp[200005][3];
bool vis[200005][3];
ll solve(int idx, int state){
  if(idx>n){
    if(state==0)return -1e15;
    return 0;
  }
  ll &ret = dp[idx][state];
  if(vis[idx][state])
    return ret;
  vis[idx][state]=1;
  ret=solve(idx+2,state)+a[idx];
  if(state<2)ret=max(ret,solve(idx+1,state+1));
  return ret;
}
void trace(int idx, int state){
  if(idx>n){
    return;
  }
  if(solve(idx+2,state)+a[idx]==solve(idx,state)){
//    cout<<idx<<' ';
    trace(idx+2,state);
  } else {
    trace(idx+1,state+1);
  }


}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin>>n;
  f(i,1,n+1){
    cin>>a[i];
    sum[i][0]=sum[i-1][0];
    sum[i][1]=sum[i-1][1];
    sum[i][i&1]+=a[i];
  }
//  cout<<solve(1,0)<<'\n';
  trace(1,0);
  if(n%2==0){
    ll ans =max(sum[n][0],sum[n][1]);
    for(int i = 1; i + 1 <= n; i++){
      int cntL[2] = {};
      int cntR[2] = {};
      cntL[1] = i / 2;
      cntL[0] = (i-1) / 2;
      cntR[1] = n / 2 - (i+2)/2;
      cntR[0] = n / 2 - (i + 1) / 2;
      f(x,0,2)
        f(y,0,2){
//          cout<<cntL[x]<<' '<<cntR[y]<<'\n';
          assert((cntL[x]+cntR[y])<=n/2);
          if(cntL[x]+cntR[y]==n/2){
            ans=max(ans,sum[i-1][x]+sum[n][y]-sum[i+1][y]);
          }
        }
    }
    cout<<ans<<'\n';
  } else {
    ll ans =max(sum[n][0],sum[n-1][1]);
    ans=max(ans,sum[n][1]-sum[1][1]);
    for(int i = 1; i + 1 <= n; i++){
      int cntL[2] = {};
      int cntR[2] = {};
      cntL[1] = i / 2;
      cntL[0] = (i-1) / 2;
      cntR[1] = (n+1) / 2 - (i+2)/2;
      cntR[0] = n / 2 - (i + 1) / 2;
      f(x,0,2)
        f(y,0,2){
//          cout<<cntL[x]<<' '<<cntR[y]<<'\n';
          assert((cntL[x]+cntR[y])<=n/2);
          if(cntL[x]+cntR[y]==n/2){
            ans=max(ans,sum[i-1][x]+sum[n][y]-sum[i+1][y]);
          }
        }
    }
    cout<<max(ans,solve(1,0))<<'\n';
  }

  return 0;
}


Measured memory_bytes: 18296
import sys
N = int(input())
boxes = list(map(int,input().split()))
prev = 10**9+1
for box in boxes[::-1]:
    if prev - box > -1:
        prev = box
    elif prev - box == -1:
        prev = box -1
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 14396
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  map<long, long> mp;
  long N;
  cin >> N;
  rep (i, N) {
    long A;
    cin >> A;
    mp[A] = i+1;
  }
  bool flag = false;
  for (auto it: mp) {
    if (flag) cout << " ";
    flag = true;
    cout << it.second;
  }
  cout << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 7040
#include <iostream>
using namespace std;
int c[101][100];
int cn[101];
int maxchain(int m,int l,bool inchain[101]){
	int ml=l;
	for(int i=0;i<cn[m];i++){
		if(!inchain[c[m][i]]){
			inchain[c[m][i]]=true;
			int ll=maxchain(c[m][i],l+1,inchain);
			if(ml<ll){ml=ll;}
			inchain[c[m][i]]=false;
		}
	}
	return ml;
}
int main() {
	while(1){
		int n;
		cin >> n;
		if(n==0){break;}
		int s[2][n];
		for(int i=1;i<=100;i++){
			cn[i]=0;
		}
		for(int i=0;i<n;i++){
			cin >> s[0][i] >> s[1][i];
			c[s[0][i]][cn[s[0][i]]]=s[1][i];
			cn[s[0][i]]++;
			c[s[1][i]][cn[s[1][i]]]=s[0][i];
			cn[s[1][i]]++;
		}
		int ml=0;
		for(int i=1;i<=100;i++){
			int l=1;
			bool inchain[101];
			for(int j=1;j<101;j++){
				inchain[j]=false;
			}
			inchain[i]=true;
			l=maxchain(i,l,inchain);
			if(ml<l){
				ml=l;
			}
		}
		cout << ml << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
n = int(input())
data = [int(i) for i in input().split(' ')]

def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i + 1, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
        
bubble_sort(data)

Measured memory_bytes: 7752
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll N;
    cin >> N;

    vector<ll> X(5);
    string S;

    rep(i, 5) {
        X[i] = 0;
    }


    rep(i, N) {
        cin >> S;
        if (S[0] == 'M') {
            X[0]++;
        }
        if (S[0] == 'A') {
            X[1]++;
        }
        if (S[0] == 'R') {
            X[2]++;
        }
        if (S[0] == 'C') {
            X[3]++;
        }
        if (S[0] == 'H') {
            X[4]++;
        }
    }

    ll ans = 0;

    repl(i, 0, 3) {
        repl(j, i + 1, 4) {
            repl(k, j + 1, 5) {
                ans += X[i] * X[j] * X[k];
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    int res = y * 10000 + m * 100 + d;
    if(res <= 2019*10000+4*100+30)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;

    return 0;
}


Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

int n, a, b;

int main() {	
    #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    //~ freopen(NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(9) << fixed;

	cin >> n >> a >> b;
	
	bool t = 0;
	int Apos = a, Bpos = b;
	
	while (true) {
		//~ cout << Apos << ' ' << Bpos << '\n';
		if (t == 0) {
			if (Apos + 1 == Bpos) {
				cout << "Borys";
				return 0;
			}
			else Apos++;
		}
		else {
			if (Bpos - 1 == Apos) {
				cout << "Alice";
				return 0;
			}
			else Bpos--;
		}
		t ^= 1;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
y = [0]*(N+1)
for i in range(1,N+1):
    M = i
    while M > 1:
        for j in range(2,M+1):
            if M%j == 0:
                M = M//j
                y[j] += 1
                break
ans = 1
for i in y:
    ans = (ans*(i+1))%(10**9+7)
print(ans)

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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	cout << *min_element(all(v)) << " ";
	cout << *max_element(all(v)) << " ";
	cout << accumulate(all(v), 0LL) << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    set<string> st;
    rep(i,n){
        string a;
        cin >> a;
        st.insert(a);
    }
    if(n == st.size()){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 23680
#include <stdio.h>

int n,s;

int ans;

//depth first search
void dfs(int i,int sum,int n) {

  //³ð
  if((sum==s) && (n==0)) {

    ans++;
    return;

  }

  //s³ð
  if((i==10) || (n==0)) return;

  //Tõr
  dfs(i+1,sum,n); //iðgíÈ¢p^[(±êð»êÈãÅ«È­ÈéÜÅ±¯é)
  dfs(i+1,sum+i,n-1); //iðg¤p^[

}

int main(void) {

  while(scanf("%d %d",&n,&s)!=EOF) {

    if((n==0) && (s==0)) break;

    ans=0;

    dfs(0,0,n);

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

  }

  return 0;

}
      

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  ll N;
  cin>>N;

  int a[N][N-1];

  rep(i,N){
    rep(j,N-1){
      int aa; cin>>aa; --aa;
      a[i][j]=aa;
    }
  }

  int now[N]={};
  bool dame[N]={};
  bool update =true;
  int ct=0;
  while(update){
    update=false;
    ct++;
    rep(i,N){
      if(dame[i]){dame[i]=false; continue;}
      if(now[i]>=N-1) continue;
      int saki=a[i][now[i]];
      if(saki>i and a[saki][now[saki]]==i and !dame[saki]){
        ++now[i]; ++now[saki]; update=true; dame[saki]=true;
      }
    }
  }
  rep(i,N){
    if(now[i]<N-1){
      cout<< -1<<"\n"; return;
    }
  }
  cout<< ct-1 <<"\n";
}

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


Measured memory_bytes: 4224
def main():
    import sys
    readline = sys.stdin.buffer.readline

    from collections import deque

    h, w = map(int, readline().split())
    s = ['#'*(w+2)] + ['#' + readline().rstrip().decode('utf-8') + '#' for _ in range(h)] + ['#'*(w+2)]

    l = []
    for i in range(h+2):
        for j in range(w+2):
            if s[i][j] == '.':
                l.append((i, j))
    dire = ((0, 1), (0, -1), (1, 0), (-1, 0))
    q = deque()
    ans = 0
    for hh, ww in l:
        q.appendleft((hh, ww, 0))
        c = [[0]*(w+2) for _ in range(h+2)]
        while q:
            ha, wa, ca = q.pop()
            if c[ha][wa] == 0:
                c[ha][wa] = 1
                ans = max(ans, ca)
                for dh, dw in dire:
                    hdh, wdw = ha+dh, wa+dw
                    if s[hdh][wdw] == '.' and c[hdh][wdw] == 0:
                        q.appendleft((hdh, wdw, ca+1))
    print(ans)

main()

Measured memory_bytes: 9468
#include <iostream>
using namespace std;
int main()
{
	long long n,b,s=1;
	cin>>b>>n;
	while(true){
		if(b*2<=n){
			s++;
			b*=2;
		}
		else{
			cout<<s;
			return 0;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x;
    for(int i = 0; i < n; ++i) {
        int buffer;
        cin >> buffer;
        x.emplace_back(buffer);
    }

    sort(x.begin(), x.end());

    int mn = x[0];
    int mx = x[n-1];

    int ans = 2147483647;

    for(int i = 0; i < mx+1; ++i) {
        int sum = 0;
        for(auto p : x) {
            sum += pow((p - i), 2);
        }

        ans = min(ans, sum);
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  long n;
  cin >> n;
  long a[n], b[n], c[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n; i++){
    cin >> c[i];
  }
  sort(a,a+n);
  sort(c,c+n);
  long cnta, cntc;
  long ans = 0;
  for(int i = 0; i < n; i++){
    cnta = lower_bound(a,a+n,b[i]) - a;
    cntc = c+n - upper_bound(c,c+n,b[i]);
    ans += cnta * cntc;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]){
    printf("Yes\n");
  } else if (s[1] == s[2] && s[2] == s[3]) {
    printf("Yes\n");
  } else {
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repe(i, n) for(int i = 0; i <= (n); i++)
#define fo(i, a, b) for(int i = (a); i < (b); i++)
#define foe(i, a, b) for(int i = (a); i <= (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<long long>::max();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


int main() {

	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	int ans = INTMAX;

	for (int s = 0, e = s + k; s + k <= n; s++, e++) {
		int d = 0;
		if (x[s] < 0) d += -x[s] * 2;
		d += abs(x[e - 1]);
		ans = min(d, ans);
	}
	std::reverse(x.begin(), x.end());
	for (auto& v : x) v = -v;
	for (int s = 0, e = s + k; s + k <= n; s++, e++) {
		int d = 0;
		if (x[s] < 0) d += -x[s] * 2;
		d += abs(x[e - 1]);
		ans = min(d, ans);
	}

	cout << ans NL;

	return 0;

}


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

using i64 = long long int;

int dp[200005] = {0};

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

    dp[v[0]] = 1;
    int ans = n;
    for(auto e : v){
        dp[e] = dp[e-1] + 1;
        ans = min(ans, n-dp[e]);
    }

    for(int i=0;i<=n;++i){
        dp[i] = 0;
    }

    for(int i=v.size()-1;i>=0;--i){
        dp[v[i]] = dp[v[i]+1] + 1;
        ans = min(ans, n-dp[v[i]]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1908
# https://atcoder.jp/contests/abc067/tasks/arc078_b
# 1とNの最短経路について注目したときに、それぞれの最適戦略を考えてみる
# 相手を負かせたい→相手側に攻めて道を塞ぐのが有利(相手のマスが少なくなるから)
# 自分が負けそう→退避して行きたい(でも相手のマスのほうが多かったらもう逆転は不可能)
# 勝者は→先にたどり着けるノードの中で多い方が勝者(同数の場合はFennecが敗者)

import sys
read = sys.stdin.readline
from collections import defaultdict, deque


def read_ints():
    return list(map(int, read().split()))


N = int(input())
graph = defaultdict(lambda: [])
for _ in range(N - 1):
    a, b = read_ints()
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def ret_dists(u):
    ret = [-1] * N
    que = deque([(u, -1, 0)])  # 現在のノード、前のノード、距離
    ret[u] = 0
    while que:
        u, p, d = que.popleft()
        nd = 1 + d
        for nu in graph[u]:
            if nu == p:  # 親はもう探索しない
                continue
            ret[nu] = nd
            que.append((nu, u, nd))

    return ret


fennec_dist = ret_dists(0)
snuke_dist = ret_dists(N - 1)

n_snuke = 0  # snukeに近いノードの数
n_fennec = 0  # 0を含んでfennecに近い #fennecが濡れるので
for f, s in zip(fennec_dist, snuke_dist):
    if f > s:  # すぬけにちかい
        n_snuke += 1
    else:
        n_fennec += 1

# print(n_fennec, n_snuke)
if n_fennec > n_snuke:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 75868
N,K=map(int,input().split())
Sushi=[[int(i) for i in input().split()] for j in range(N)]
Sushi=sorted(Sushi,key=lambda x:x[1],reverse=True)
inp={}
for t,d in Sushi:
    if not t in inp:
        inp[t]=d#それぞれのネタの最大値が入る
tasty=0
neta=set()#何種類か数える
dup=[]
for i in range(K):
    t,d=Sushi[i]
    tasty+=d
    if t in neta:
        dup.append((t,d))#値が大きい順に入る
    neta.add(t)
    if t in inp:
        del inp[t]
variety=len(neta)
max_tasty=tasty+variety**2
for s,t in sorted(inp.items(),key=lambda x:x[1],reverse=True):
    if len(dup):
        s1,t1=dup.pop()#一番値が小さい要素が出てくる
        variety+=1
        tasty=tasty-t1+t
        max_tasty=max(max_tasty,tasty+variety**2)
print(max_tasty)
    

Measured memory_bytes: 33996
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-28 14:43:49
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
#define int long long 
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int32_t main()
{
    int h;
    cin >> h;
    int ans = 0;
    int tmp = 1;
    while(h){
        h /= 2;
        ans += tmp;
        tmp *= 2;
    }
    cout << ans << endl;
    system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

Measured memory_bytes: 504
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
const int maxn = 10007;
const int inf =1e9;
using namespace std;
struct node{
	int to,d,c;
	node(){}
	node (int to,int d,int c):to(to),d(d),c(c){}
};
vector<node>mp[maxn];
int dis[maxn],cost[maxn],n,m,ans = 0;
void init(){
	for(int i=1;i<=n;i++)
	{
		mp[i].clear();
		dis[i] = inf;
		cost[i]  = 0;
	}
}
void add(int u,int v,int d,int c)
{
	mp[u].push_back(node(v,d,c));
}
int main(){
	while(~scanf("%d%d",&n,&m))
	{
		if(n==0&&m==0)break;
		init();
		for(int i=1;i<=m;i++)
		{
			int u,v,d,c;
			scanf("%d%d%d%d",&u,&v,&d,&c);
			add(u,v,d,c);
			add(v,u,d,c);
		}
		priority_queue<pair<int,int> >q;
		dis[1]=0;
		cost[1]=0;
		
		q.push (make_pair(-dis[1],1)) ;
		while(!q.empty())
		{
			int now = q.top().second;
			q.pop();
			for(int i=0;i<mp[now].size();i++)
			{
				int v=mp[now][i].to;
				int d=mp[now][i].d;
				int c=mp[now][i].c;
				if(dis[v]>dis[now]+d)
				{
					dis[v] = dis[now]+d;
					//ans -=cost[v];
					//cost[v] = cost[now]+c;
					//ans +=cost[v];
					q.push (make_pair(-dis[v],v));
				}
			}
		}
		ans = 0;
		for(int i=2;i<=n;i++)
		{
			int minc = inf;
			for(int j=0;j<mp[i].size();j++)
			{
				node tmp = mp[i][j];
				if(tmp.d+dis[tmp.to]==dis[i]&&minc>tmp.c)
				{
					minc = mp[i][j].c;
				}
			}
			ans += minc;
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 5140
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
long long int MOD=1000000007;
bool used[100005];
int nums[100005]={0};
int main(){
	rep(i,100005)used[i]=false;
	used[0]=true;
	int n,m;
	cin>>n>>m;
	int x,y;
	rep(i,n)nums[i]=1;
	for(int i=0;i<m;i++){
		cin>>x>>y;x--;y--;
		nums[x]--;nums[y]++;
		if(used[x]){
			used[y]=true;
			if(nums[x]==0)used[x]=false;
		}
	}
	int ans=0;
	rep(i,n)if(used[i])ans++;
	cout<<ans<<endl;
}

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

const int bound = 5050;
bool dp[bound][bound];

void init(){
	for( int i = 0; i < bound; ++i ){
		for( int j = 0; j < bound; ++j ){
			dp[i][j] = false;
		}
	}
}

int main(){
	int n, k; cin >> n >> k; 
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	sort( a.begin(), a.end() );
	int ok = -1, ng = lower_bound( a.begin(), a.end(), k ) - a.begin();
	int target;
	while( abs(ok-ng) > 1 ){
		init();
		dp[0][0] = true;
		target = (ok+ng)/2;
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j <= 5000; ++j ){
				dp[i+1][j] = dp[i][j];
				if( i == target ) continue;
				if( j >= a[i] ) dp[i+1][j] |= dp[i][j-a[i]];
			}
		}
		bool flag = false;
		for( int j = k-a[target]; j < k; ++j ){
			if( dp[n][j] ) flag = true; 
		}
		if( flag ){
			ng = target;
		} else {
			ok = target;
		}
	}
	cout << ok+1 << endl;
}


Measured memory_bytes: 25216
n, a, b, c = map(int,input().split())
l = [int(input()) for i in range(n)]

def dfs(x, y, z, now):

    if now == n:
        return abs(x - a) + abs(y - b) + abs(z - c) - 30 if not 0 in (x, y, z) else 3000

    usea = dfs(x + l[now], y, z, now + 1) + 10
    useb = dfs(x, y + l[now], z, now + 1) + 10
    usec = dfs(x, y, z + l[now], now + 1) + 10
    nouse = dfs(x, y, z, now + 1)
    return min(usea, useb, usec, nouse)

print(dfs(0,0,0,0))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==3){
    cout<<2<<' '<<3<<' '<<25<<endl;
    return 0;
  }
  cout<<2<<' '<<4<<' '<<3<<' '<<9;
  int k=4;
  for(int i=1;i*6+4<=30000&&k<=n-2;i++,k+=2)
    cout<<' '<<i*6+2<<' '<<i*6+4;
  for(int i=1;i*12+9<=30000&&k<=n-2;i++,k+=2)
    cout<<' '<<i*12+3<<' '<<i*12+9;
  for(int i=1;i*6<=30000&&k<n;i++,k++)
    cout<<' '<<i*6;
  cout<<endl;
}

Measured memory_bytes: 3640
#include<stdio.h>

int solve(int,int);
  

int n,q;
int a[20];
int m[200];

int main(){
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  scanf("%d",&q);

  for(j=0;j<q;j++){
    scanf("%d",&m[j]);
  }

  for(j=0;j<q;j++){
    if(solve(0,m[j])) printf("yes\n");
    else printf("no\n");
  }

  return 0;

}

int solve(int i,int m){
  int res;
  if(m==0) return 1;
  if(i>=n||m<0) return 0;

  if(solve(i+1,m)||solve(i+1,m-a[i])) return 1;
}

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

int main(){
    unsigned long N;
    cin >> N;
    vector<unsigned long> C(N), V(N), ans(N);
    for(auto& i : V)cin >> i;
    for(auto& i : C)cin >> i;
    transform(V.cbegin(), V.cend(), C.cbegin(), ans.begin(), [](auto a, auto b){return max(a, b) - b;});
    cout << accumulate(ans.cbegin(), ans.cend(), 0UL) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> C(N - 1), S(N - 1), F(N - 1);
	for (int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];
	for (int i = 0; i < N - 1; i++) {
		int t = 0;
		for (int current = i, n = 0; current < N - 1; current++) {
			// departure time
			int t1 = S[current] + F[current] * n;
			// arrival time of the next station
			t = t1 + C[current];
			n = max(0.0, ceil(((double)t - S[current + 1]) / F[current + 1]));
		}
		cout << t << endl;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,i;
    int ten_a,ten_b;
    int a[10001] = {0},b[10001] = {0};
    while(1){
        ten_a = ten_b = 0;
        scanf("%d",&n);
        if(n == 0) break;
        for(i = 0; i < n; i++){
            scanf("%d %d",&a[i],&b[i]);
            if(a[i] > b[i]){
                ten_a = ten_a + a[i] + b[i];
            }
            if(a[i] < b[i]){
                ten_b = ten_b + a[i] + b[i];
            }
            if(a[i] == b[i]){
                ten_a += a[i];
                ten_b += b[i];
            }
        }
        printf("%d %d\n",ten_a,ten_b);
    }
    return 0;
}

Measured memory_bytes: 684
#include <iostream>
using namespace std;
int main()
{
	int a, b,i;
	int t = 0;
	cin >> a >> b;
	for (i = 0; i < 2; ++i) {
		if (a > b) {
			t += a;
			--a;
		}
		else {
			t += b;
			--b;
		}
	}
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 256