akhauriyash/Code-Regression huggingface dataset:
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 200001;
const int mod = 1000000007;

ll h[MAXN];
ll a[MAXN];

template<typename T>
class SegTree{  //generic segment Tree
    private:

        T *tree;
        int N;
        int ZERO; // Zero value for query

        T combine(T x, T y){    //define the combine function here
            return max(x,y);
        }

        void build(){
            for(int i = N-1; i > 0; i--){
                tree[i] = combine(tree[i<<1] , tree[i<<1|1]);
            }
        }

    public:

        SegTree(int n){
            ZERO = 0; // define zero value here
            tree = new T[2*n];
            for(int i = 0; i < n; i++)tree[n+i] = ZERO;
            N = n;
            build();
        }

        T query(int l, int r){
            l += N;
            r += N;

            T ret = ZERO;

            while(l <= r){
                if(l&1)ret = combine(ret, tree[l++]);
                if(!(r&1))ret = combine(ret, tree[r--]);
                l >>= 1;
                r >>= 1;
            }

            return ret;
        }

        void pointUpdate(int pos, T val){
            pos += N;
            tree[pos] = val;
            while(pos > 1){
                pos >>= 1;
                tree[pos] = combine(tree[pos<<1], tree[pos<<1|1]);
            }
        }

};

SegTree<ll> st(MAXN);

int main(){
    int n;
    cin>>n;
    fr(i,n)cin>>h[i];
    fr(i,n)cin>>a[i];

    ll ans = 0;

    for(int i = 0; i < n; i++){
        ll mx = st.query(0,h[i]-1);
        ans = max(ans, mx + a[i]);
        st.pointUpdate(h[i]-1, mx+a[i]);
    }

    cout<< ans << endl;

}


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

bool is_prime(ll x) {
  if (x == 1) return false;
  for (int factor = 2; factor <= sqrt(x); factor++) {
    if (x % factor == 0) {
      return false;
    }
  }
  return true;
}

ll next_prime(ll prime) {
  for (ll i = prime + 1; i <= LLONG_MAX; i++) {
    if (is_prime(i)) {
      return i;
    }
  }
}

bool can_divide(ll n, ll z) { return n % z == 0; }

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

  ll counter = 0;
  ll divisor;
  ll last_prime = 2;

  for (ll p = 2; p <= n; p = next_prime(p)) {
    // printf("p: %lld, n: %lld\n", p, n);

    if (p > sqrt(n)) {
      break;
    }

    for (int e = 1; pow(p, e) <= n; e++) {
      divisor = pow(p, e);
      if (!can_divide(n, divisor)) {
        if (can_divide(n, p)) {
          n /= p;
        }
        break;
      }
      n /= divisor;
      // printf("p: %lld, e: %d, n: %lld\n", p, e, n);
      counter++;
    }

    last_prime = p;
  }

  if (is_prime(n) && n > last_prime) {
    counter++;
  };

  cout << counter << endl;
}

Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
        int n; scanf("%d", &n);

        vector<vector<P>> xy(n, vector<P>(0));
        for(int i=0; i<n; i++){
                int a; scanf("%d", &a);
                for(int j=0; j<a; j++){
                        int x, y;
                        scanf("%d %d", &x, &y);
                        xy[i].push_back(make_pair(x-1, y));
                }
        }

        int ans = 0;
        for(int i=0; i<(1<<n); i++){
                vector<bool> hone(n), evil(n);
                for(int j=0; j<n; j++) hone[j]=0, evil[j]=0;

                int tmp=0;
                for(int j=0; j<n; j++){
                        if((i>>j)&1){
                                tmp++;
                                if(evil[j]) tmp = -1e9;
                                else hone[j] = 1;
                                for(P pr: xy[j]){
                                        if(pr.second){
                                                if(!evil[pr.first]) hone[pr.first] = 1;
                                                else tmp = -1e9;
                                        }else{
                                                if(!hone[pr.first]) evil[pr.first] = 1;
                                                else tmp = -1e9;
                                        }
                                }
                        }else{
                                if(hone[j]) tmp=-1e9;
                                else evil[j] = 1;
                        }
                }
                ans = max(ans, tmp);
        }
        printf("%d\n", ans);
        return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var items = Console.ReadLine().Split(' ');
        var num = int.Parse(input[1]);

        var count = 0;

        var sum = 0;

        foreach(var item in items)
        {
            sum += int.Parse(item);
        }

        foreach (var item in items)
        {
            if (sum % (4 * num) == 0)
            {
                if (int.Parse(item) >= sum / (4 * num))
                {
                    count += 1;
                }
            }
            else
            {
                if (int.Parse(item) > sum / (4 * num))
                {
                    count += 1;
                }
            }
        }

        if(count >= num)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");

        }
        Console.ReadLine();
    }
}



Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//UnionFind木のテンプレ.parentには根のindexが入っている.
//根には連結成分のサイズが入っている.nはノード数.
class UnionFind{
public:
	vector<int> parent;
	UnionFind(){}
	UnionFind(int n){
		this->parent = vector<int>(n,-1);
	}
	int root(int x){
		if (this->parent[x] < 0) return x;
		this->parent[x] = root(this->parent[x]);
		return this->parent[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return false;
		if (this->parent[rx] > this->parent[ry]) swap(rx, ry);
		this->parent[rx] += this->parent[ry];
		this->parent[ry] = rx;
		return true;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->parent[this->root(x)];
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	rep(i,q){
		int t, u, v;
		cin >> t >> u >> v;
		if(t == 0){
			uf.unite(u, v);
		} else {
			cout << uf.same(u, v) << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3980
#https://atcoder.jp/contests/abc147/submissions/8879507
H, W = gets.split.map(&:to_i)
A = H.times.map{gets.split.map(&:to_i)}
B = H.times.map{gets.split.map(&:to_i)}
M = 80*(H+W)
X = Array.new(H){Array.new(W, 0)}
H.times do |i|
  W.times do |j|
    X[i][j] = (A[i][j]-B[i][j]).abs
  end
end

dp = Array.new(H){Array.new(W, 0)}
dp[0][0] = 1 << (M - X[0][0]) | 1 << (M + X[0][0])
H.times do |i|
  W.times do |j|
    d = X[i][j]
    if i > 0
      dp[i][j] |= dp[i - 1][j] << d 
      dp[i][j] |= dp[i - 1][j] >> d
    end
    if j > 0
      dp[i][j] |= dp[i][j - 1] << d 
      dp[i][j] |= dp[i][j - 1] >> d
    end
  end
end
h = dp[H - 1][W - 1]
puts M.times.find{|i| h[M - i] > 0 || h[M + i] > 0 }

Measured memory_bytes: 51324
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;

string name;
inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

int main()
{
    quickread();
    cin >> name;
    cout << name[0]<< name[1]<<name[2] << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main()
{
    cin.tie(nullptr);

    int N, M;
    std::cin >> N >> M;
    std::vector<std::vector<int>> C(N);
    for (int i = 0; i < M; ++i)
    {
        int A, B;
        std::cin >> A >> B;
        A--;
        B--;
        C[A].emplace_back(B);
        C[B].emplace_back(A);
    }

    std::vector<int> next(N, -1);
    std::vector<int> flag(N, 0);

    std::queue<int> q;
    q.push(0);
    next[0] = 0;
    while (!q.empty())
    {
        int const index = q.front();
        q.pop();
        if (flag[index])
            continue;
        flag[index] = 1;
        for (auto const n : C[index])
        {
            if (next[n] == -1)
            {
                next[n] = index;
                q.push(n);
            }
        }
    }
    for (auto const n : next)
    {
        if (n == -1)
        {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes\n";
    for (int i = 1; i < N; ++i)
    {
        std::cout << next[i] + 1 << "\n";
    }
    std::cout << std::flush;

    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	double x[n], y[n], d1 = 0, d2 = 0, d3 = 0, de = 0;
	for (int i = 0; i < n; i++)cin >> x[i];
	for (int i = 0; i < n; i++) {
		cin >> y[i];
		double f = fabs(x[i] - y[i]);
		d1 += f;
		d2 += f * f;
		d3 += f * f * f;
		de = max(de, f);
	}
	printf("%.6f\n%.6f\n%.6f\n%.6f\n", d1, sqrt(d2), pow(d3, 1.0 / 3.0), de);
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int64_t r = 0, g = 0, b = 0, rgb = 0;
    for (auto i = 0; i < n; i++) {
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
    }
    b = n - r - g;
    if(r == 0 or b == 0 or g == 0) {
        cout << 0 << endl;
        return 0;
    }

    for (auto i = 0; i < n; i++) {
        for (auto j = 1; j < n; j++) {
            if((i + j * 2) >= n) continue;
            if(s[i] != s[i + j] and s[i + j] != s[i + j * 2] and s[i + j * 2] != s[i]) rgb++;
        }
    }

    cout << r*g*b - rgb << endl;
    return 0;

//    int ans = 0;
//    for (auto i = 0; i < r.size(); i++) {
//        for (auto j = 0; j < g.size(); j++) {
//            for (auto k = 0; k < b.size(); k++) {
//                int min_index = min(min(r[i], g[j]), b[k]);
//                int max_index = max(max(r[i], g[j]), b[k]);
//                int middle = r[i] + g[j] + b[k] - (min_index + max_index);
//                if(middle - min_index != max_index - middle) ans++;
//            }
//        }
//    }
//
//    cout << ans << endl;
//    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 21000;
const int MOD = 1000000007;

ll dp[MAX][260];
// dp[i][j] は i個までみた時 現在 j の最小値

int main(){
  vector<ll> ans;
  while(1){
    ll N ,M; cin >> N >> M;
    if(N == 0 and M == 0) break;
    vector<ll> c(M); rep(i,M) cin >> c[i];
    vector<ll> x(N); rep(i,N) cin >> x[i];
    // dp table 初期化
    rep(i,MAX) rep(j,260) dp[i][j] = INF;
    dp[0][128] = 0;
    rep(i,N){
      rep(j,256){
        rep(k,M){
          // from j to j + c[k]をそれぞれ追っていく
          if(j + c[k] < 0){
            dp[i + 1][0] = min(dp[i + 1][0] , dp[i][j] + x[i] * x[i]);
          }
          else if(j + c[k] > 255){
            dp[i + 1][255] = min(dp[i + 1][255] , dp[i][j] + (255 - x[i]) * (255 - x[i]) );
          }
          else{
            dp[i + 1][j + c[k]] = min(dp[i + 1][j + c[k]] , dp[i][j] + (j + c[k] - x[i]) * (j + c[k] - x[i]) );
          }
        }
      }
    }
    // rep(i,N + 1) for(ll j = 255; j < 256; j++) cout << i << " " << j << " " <<  dp[i][j] << endl;

    ll tmp = INF;
    rep(j,256) tmp = min(tmp , dp[N][j]);
    ans.pb(tmp);
  }
  rep(i,ans.size()) cout << ans[i] << endl;
}



Measured memory_bytes: 45852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll MOD = 1e9 + 7;

ll modpow(ll a, ll b, ll m) {
  if (b == 0) return 1;
  ll ret;
  if (b % 2 == 0) {
    ll t = modpow(a, b / 2, m) % m;
    ret = t * t % m;
  } else {
    ll t = modpow(a, (b - 1) / 2, m) % m;
    ret = a * t % m * t % m;
  }
  ret %= m;
  return ret;
}

/* 二項係数 C(n,k) mod p を計算 */
const int MAX = 201000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll n;
  cin >> n;
  ll m = 60;
  vector<ll> a(n);
  vector<vector<ll>> b(n, vector<ll>(m, 0));
  REP(i, n) {
    cin >> a[i];

    ll tmp = a[i];
    REP(j, m) {
      if (tmp % 2 != 0) {
        b[i][j] = 1;
      }
      tmp /= 2;
    }
  }
  // REP(i, n) REP(j, m) { cout << b[i][j] << " \n"[j == m - 1]; }
  // k bit 目の1の数

  vector<ll> cnt(m, 0);
  REP(i, n) {
    REP(j, m) {
      if (b[i][j]) cnt[j]++;
    }
  }
  // REP(j, m) { cout << cnt[j] << " \n"[j == m - 1]; }

  ll ans = 0;
  REP(i, m) {
    if (cnt[i] == 0) continue;
    ll k = modpow(2, i, MOD);
    (ans += ((k * cnt[i]) % MOD * (n - cnt[i])) % MOD) %= MOD;
    // DUMP(ans);
  }
  COMinit();
  //(ans *= inv[2]) %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 159616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long M = 1e9 + 7;
int pow_2(int n)
{
    if(n <= 0) return 1;
    if(n == 1) return 2;
    long long k = pow_2(n/2) % M;
    if(n & 1) return ((((k % M) * (k % M)) % M) * 2) % M;
    else      return ((k % M) * (k % M)) % M;
}
int main()
{
    long long n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    for(int i = n-1; i > 0; i-=2){
        if(a[i] == a[i-1] && a[i] == i){
            continue;
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    if(n&1 && a[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    cout << pow_2(n/2) << endl;
    return 0;
}

Measured memory_bytes: 640
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))

Measured memory_bytes: 37964
package main

import "fmt"

func search(l, r int) (m int) {
	m = 2019
	for i := l; i < r; i++ {
		for j := i + 1; j <= r; j++ {
			if mod := (i * j) % 2019; m > mod {
				m = mod
			}
			if m == 0 {
				return 0
			}
		}
	}
	return
}

func main() {
	var l, r int
	fmt.Scan(&l, &r)

	min := search(l, r)
	fmt.Println(min)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A * A == B * B + C * C)
    {
        cout << B * C / 2 << endl;
    }
    else if (B * B == C * C + A * A)
    {
        cout << C * A / 2 << endl;
    }
    else
    {
        cout << A * B / 2 << endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int k, x;
  cin >> k >> x;
  int min = x - k + 1;
  int max = x + k - 1;
  if (min < -1000000) {
    min = -1000000;
  }
  if (max > 1000000) {
    max = 1000000;
  }

  for (int i = min; i < max; i++) {
    cout << i << " ";
  }
  cout << max;
}

Measured memory_bytes: 256
void main() {
	auto arr = 5.iota.map!(i => ri).array;
	auto k = ri;
	if(arr.back - arr.front > k) {
		writeln(":(");
	} else writeln("Yay!");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF (1<<28)

int n, f[128][128], dp[128][128];

int main() {
    rep (i, 128) rep (j, 128) f[i][j] = -INF;
    string s;
    while (getline(cin, s)) {
        rep (i, s.size()) if (s[i] == ',') s[i] = ' ';
        int k = 0;
        istringstream sin(s);
        string w;
        while (sin >> w) f[n][k++] = atoi(w.c_str());
        n++;
    }
    rep (i, 128) rep (j, 128) dp[i][j] = -INF;
    dp[0][0] = f[0][0];
    for (int i = 1; i <= n/2; i++) {
        rep (j, 128) {
            if (j > 0) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+f[i][j]);
            dp[i][j] = max(dp[i][j], dp[i-1][j]+f[i][j]);
        }
    }
    for (int i = n/2+1; i < n; i++) {
        rep (j, 128) {
            dp[i][j] = max(dp[i][j], dp[i-1][j]+f[i][j]);
            if (j < 127) dp[i][j] = max(dp[i][j], dp[i-1][j+1]+f[i][j]);
        }
    }
    printf("%d\n", dp[n-1][0]);
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second


int main()
{
    int n;
    while(cin>>n,n)
    {
        int a[n];
        REP(i,n)
        {
            string s;
            cin>>s;
            a[i]=s.size();
        }
        rep(i,0,n-4)
        {
            int j=i;
            int sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            cout<<i+1<<endl;break;
        }
    }
    
}


Measured memory_bytes: 3152
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
int main() {
	int H, N;
	scanf("%d %d", &H, &N);
	auto A = new int[N];
	auto B = new int[N];
	for (int i = 0; i < N; i++)scanf("%d %d", A + i, B + i);
	auto maxA = new int[100000000]{};
	int res = 0;
	for (int i = 0;; i++) {
		for (int j = 0; j < N; j++) {
			if (B[j] > i)continue;
			maxA[i] = maximum(maxA[i - B[j]] + A[j], maxA[i]);
		}
		if (maxA[i] >= H) {
			res = i;
			break;
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 390912
// AOJ 0184: Tsuruga Castle
// 2017.8.2 bal4u@uu
// 2017.11.12

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()

int in()
{
	int n, c;

	while ((c = getchar_unlocked()) < '0');
	n = 0;
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, c1, c2, c3, s;
	int cnt[10];

	while (n = in()) {
		memset(cnt, 0, sizeof(cnt));
		i = n; while (i--) {
			c1 = getchar_unlocked();
			c2 = getchar_unlocked();
			if (c2 < '0') { cnt[0]++; continue; }
			c3 = getchar_unlocked();
			if (c3 < '0') { cnt[c1 & 0xf]++; continue; }
			getchar_unlocked();
		}
		s = 0;
		for (i = 0; i < 6; i++) s += cnt[i], printf("%d\n", cnt[i]);
		printf("%d\n", n - s);
	}
	return 0;
}



Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class UnionFind {
  public:
    vi Parent;
    UnionFind(int N) {
      Parent = vi(N,-1);
    }
  
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }
  
    int size(int A) {
      return -Parent[root(A)];
    }
  
    bool connect(int A,int B) {
      A = root(A);
      B = root(B);
      if(A == B) return false;
      if(size(A) < size(B)) swap(A,B);
      Parent[A] += Parent[B];
      Parent[B] = A;
      return true;
    }
};

ll kruskal(vector<pair<ll,P>> &ES,int V) {
  // ES[i] = P(c,P(f,t)) means that from `f` to `t` 's cost is `c`
  sort(rng(ES));
  UnionFind tree = UnionFind(V);
  ll res = 0;
  rep(i,sz(ES)) {
    ll c = ES[i].first;
    int f = ES[i].second.first;
    int t = ES[i].second.second;
    if(tree.root(f) != tree.root(t)) {
      res += c;
      tree.connect(f,t);
    }
  }
  return res;
}
  
int main() {
  int N;
  cin >> N;
  vp xy(N),yx(N);
  rep(i,N) {
    int x,y;
    cin >> x >> y;
    xy[i] = P(x,i);
    yx[i] = P(y,i);
  }
  sort(rng(xy));
  sort(rng(yx));
  vector<pair<ll,P>> ES;
  rep(i,N-1) {
    ll c = xy[i+1].first - xy[i].first;
    int f = xy[i+1].second;
    int t = xy[i].second;
    ES.push_back(pair<ll,P>(c,P(f,t)));
    ES.push_back(pair<ll,P>(c,P(t,f)));
  }
  rep(i,N-1) {
    ll c = yx[i+1].first - yx[i].first;
    int f = yx[i+1].second;
    int t = yx[i].second;
    ES.push_back(pair<ll,P>(c,P(f,t)));
    ES.push_back(pair<ll,P>(c,P(t,f)));
  }
  cout << kruskal(ES,N) << endl;
  return 0;
}

Measured memory_bytes: 12012
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <list>

using namespace std;

void solve(int n, vector<int> a) {
    list<int> ret;
    bool flag = true;
    if (n%2 == 0) {
        flag = !flag;
    }
    for (int i = 0; i < n; i++) {
        if (flag) {
            ret.push_front(a[i]);
        } else {
            ret.push_back(a[i]);
        }
        flag = !flag;
    }
    for (int i = 0; i < n-1; i++) {
        std::cout << ret.front() << " ";
        ret.pop_front();
    }
    std::cout << ret.front() << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    solve(n, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

Measured memory_bytes: 23508
S = list(input())

ans = 'Yes'
for i, s in enumerate(S):
    if i%2 == 0:
        if not s in ['R', 'U', 'D']:
            ans = 'No'
    if i%2== 1:
        if not s in ['L', 'U', 'D']:
            ans = 'No'
print(ans)

Measured memory_bytes: 3064
<?php
/*
    Problem URL : http://abc050.contest.atcoder.jp/tasks/abc050_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d", $N);
$T = explode(" ", trim(fgets(STDIN)));
$total = array_sum($T);
fscanf(STDIN, "%d", $M);
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $P, $X);
    echo ($total - $T[$P-1] + $X) . PHP_EOL;
}


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

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    string board[50];

    for (int i = 0; i < h; i++) cin >> board[i];

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

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (board[i][j] == '#') continue;

            int c = 0;
            for (int k = 0; k < 8; k++) {
                int ni = i + dy[k];
                int nj = j + dx[k];

                if (ni < 0 || ni >= h) continue;
                if (nj < 0 || nj >= w) continue;
                if (board[ni][nj] == '#') c++;
            }

            board[i][j] = char(c + '0');
        }
    }

    for (int i = 0; i < h; i++) cout << board[i] << endl;
}


Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	static void solve() throws Exception {
		int n = scanInt();
		int nums[] = new int[20000];
		for (int i = 0, cur = 1; i < 20000; i++) {
			do {
				++cur;
			} while (cur % 2 != 0 && cur % 3 != 0);
			nums[i] = cur;
		}
		Random rng = new Random(42);
		boolean have[] = new boolean[30001];
		while (true) {
			fill(have, false);
			int sum = 0;
			boolean have2 = false, have3 = false;
			for (int i = 0; i < n - 1; i++) {
				int j = i + rng.nextInt(20000 - i);
				int t = nums[i];
				nums[i] = nums[j];
				nums[j] = t;
				sum += nums[i];
				if (nums[i] % 2 != 0) {
					have2 = true;
				}
				if (nums[i] % 3 != 0) {
					have3 = true;
				}
				have[nums[i]] = true;
			}
			if (!have2 || !have3) {
				continue;
			}
			for (int i = 1; i <= 30000; i++) {
				if (!have[i] && (sum + i) % 6 == 0 && gcd(sum, i) != 1) {
					for (int j = 0; j < n - 1; j++) {
						out.print(nums[j] + " ");
					}
					out.print(i);
					return;
				}
			}
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 26096
// @problemURL url.com
package main

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

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	fmt.Println(2.0 * math.Pi * float64(ni(s)))
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastio;
    int x, t;
    cin >> x >> t;
    if (x <= t)
        cout << 0 << endl;
    else
        cout << (x - t) << endl;
}

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

typedef long long int ll;
ll n, a[87];

int main() {
    scanf("%lld", &n);
    for(ll i = 0; i < n; ++i) scanf("%lld", &a[i]);

    ll ans = 1000;
    for(ll i = 0; i < n - 1; ++i) {
        if(a[i] < a[i + 1]) {
            ll cur = ans%a[i];
            ans = (ans/a[i]) * a[i + 1];
            ans += cur;
        }
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3816
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  string s;
  cin >> s;

  REP(bit, 4){
    vector<int> vec(N, -1);
    REP(i, 2){
      if((bit >> i)&1) vec[i] = 1;
      else vec[i] = 0;
    }

    bool ans = true;
    FOR(i, 1, N+1){
      if(vec[(i+1)%N] == -1){
        if(vec[i%N]){
          if(s[i%N] == 'o') vec[(i+1)%N] = vec[(i-1)%N];
          else vec[(i+1)%N] = 1-vec[(i-1)%N];
        }else{
          if(s[i%N] == 'o') vec[(i+1)%N] = 1-vec[(i-1)%N];
          else vec[(i+1)%N] = vec[(i-1)%N];
        }
      }else{
        if(vec[i%N]){
          if(s[i%N] == 'o') if(vec[(i+1)%N] != vec[(i-1)%N]) ans = false;
          if(s[i%N] == 'x') if(vec[(i+1)%N] != 1-vec[(i-1)%N]) ans = false;
        }else{
          if(s[i%N] == 'x') if(vec[(i+1)%N] != vec[(i-1)%N]) ans = false;
          if(s[i%N] == 'o') if(vec[(i+1)%N] != 1-vec[(i-1)%N]) ans = false;
        }
      }
    }
    if(ans){
      REP(i, N){
        if(vec[i]) cout << "S";
        else cout << "W";
      }
      cout << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

#define LEN 3

int main(void) {
    char s[LEN];
    char t[LEN];
    int i;
    int c = 0;
    
    scanf("%s", s);
    scanf("%s", t);

    for (i = 0; i < LEN; i++) {
        if (s[i] == t[i]) {
            c++;
        }
    }
    printf("%d\n", c);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int reversed  = 0;
  string l,r;
  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    int t;
    cin >> t;
    if (t==1){
      reversed=1-reversed;
    }
    else{
      int t_a;
      cin >> t_a;
      if(reversed==0&&t_a==1){
        string j;
        cin >> j;
        l=j+l;
      }  
      else if(reversed==1&&t_a==2){
        string j;
        cin >> j;
        l=j+l;
      }
      else if(reversed==0&&t_a==2){
        string j;
        cin >> j;
        r=r+j;
      }
      else{
        string j;
        cin >> j;
        r=r+j;
      }
    }
  }
  string ans=l+s+r;
  if(reversed==1){
    reverse(ans.begin(),ans.end());
  }
  cout << ans <<endl;
}

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

int main(){
    ll N; cin >> N;
    vector<ll> p(N),q(N);
    rep(i,N){
        cin >> p[i];
        q[i] = p[i];
    }
    ll cnt=0;
    sort(q.begin(),q.end());
    rep(i,N){
        if(p[i] != q[i])cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

const long long INF = 1LL << 60;

int n,k;
long long h[100010];

long long dp[100010];

int main() {
  cin >> n >> k;
  rep(i,n) cin >> h[i];
  rep(i,100010) dp[i] = INF;
  dp[0] = 0;
  for(int i = 0;i < n;i++) {
    for(int j = 1;j <= k;j++) {
      chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    long long n, ans = 1; cin >> n;
    rep(i, 1, n + 1) {
        ans = ans * i % 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define endl "\n"
 
using namespace std;

const int mlt=(1<<18)+69;
const ll inf=1e18;
//TTBDC

int main()
{
  fatafat
  int n;
  cin>>n;
  ll ans=0,x;
  ll mx=0;
  for(int i=0;i<n;i++){
    cin>>x;
    if(x<mx)ans+=mx-x;
    mx=max(mx,x);
  }
  cout<<ans;
  return 0;
}

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

using namespace std;

int main()
{
    int x,t,f=0,m=1;
    cin>>x;
    for(int i=x;i>=1;i--)
    {
        for(int j=i-1;j>=2;j--)
        {
            t=i;
            while(t%j==0)
            {
                t/=j;
            }
            if(t==1)
            {
              //  printf("i%d  \n ",i);
                if(i>m) m=i;
            }
        }
    }
    cout<<m<<endl;

    return 0;
}


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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=1e3+10;

int h,w,n;
int cnt[20];
int sum[15][maxn];
int ans=mod;

void solve(int mask) {
	memset(cnt,0,sizeof(cnt));
	vector<int>l;
	int cur=0;
	for (int i=0;i<h-1;i++)
		if ((mask>>i)&1) l.pb(i),cur++;
	l.pb(h-1);
	for (int i=0;i<w;i++) 
		for (int j=0;j<SZ(l);j++) {
			cnt[j]+=sum[l[j]][i];
			if (j!=0) cnt[j]-=sum[l[j-1]][i];
			if (cnt[j]>n) {
				cur++;
				for (int k=0;k<SZ(l);k++) {
					cnt[k]=sum[l[k]][i];
					if (k!=0) cnt[k]-=sum[l[k-1]][i];
					if (cnt[k]>n) return;
				} 
				break;
			}
		}
	ans=min(ans,cur);
}

int main(){
	scanf("%d%d%d",&h,&w,&n);
	for (int i=0;i<h;i++) {
		scanf("\n");
		for (int j=0;j<w;j++) {
			char x;
			scanf("%c",&x);
			if (i==0) sum[i][j]=(x=='1');
			else sum[i][j]=sum[i-1][j]+(x=='1');
		}
	}
	for (int i=0;i<(1<<(h-1));i++) solve(i);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int[] dims = new int[n + 1];
            for (int i = 0; i < n; i++)
            {
                var strs = Console.ReadLine().Split(' ');
                dims[i] = int.Parse(strs[0]);
                dims[i + 1] = int.Parse(strs[1]);
            }
            int[,] cost = new int[n + 1, n + 1];
            for (int len = 2; len <= n; len++)
            {
                for (int i = 0; i < n - len + 1; i++)
                {
                    int j = i + len - 1;
                    cost[i, j] = int.MaxValue;
                    for (int k = i; k < j; k++)
                    {
                        var tmp = cost[i, k] + cost[k + 1, j] + dims[i] * dims[k + 1] * dims[j + 1];
                        if (tmp < cost[i, j]) cost[i, j] = tmp;
                    }
                }
            }
            Console.WriteLine(cost[0, n - 1]);
        }
    }
}

Measured memory_bytes: 9144
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<=10000;i++){
		int rem=a-i*100;

		if(rem<0){
			continue;
		}
		if(rem<=5*i){
			printf("1\n");return 0;
		}
	}
	printf("0\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


vector<bool> prime_table(int n) {
    vector<bool> prime(n + 1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(!prime[i]) continue;
        for(int j = i + i; j <= n; j += i) {
        prime[j] = false;
        }
    }
    return prime;
}


//keyより小さいxの個数
int LessThan_X(vector<int> &v, int key){
    return distance(v.begin(), lower_bound(all(v), key));
}

//keyより大きいxの個数
int GreaterThan_X(vector<int> &v, int key){
    return distance(upper_bound(all(v), key), v.end());
}


int main(){
    int lim = 1e5 + 1;
    vector<int> like_n;

    vector<bool> is_prime = prime_table(lim);
    for(int i=1; i<=lim; i+=2){
        if(is_prime[i]){
            if(is_prime[(i+2)/2]) like_n.push_back(i);
        }
    }

    int q;
    cin >> q;
    rep(i, q){
        int ans = 0;
        int l, r;
        cin >> l >> r;
        ans += like_n.size() - LessThan_X(like_n, l) - GreaterThan_X(like_n, r);
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int w,n,a[31],b[31],last[31];
	char f;
	cin>>w>>n;
	for(int i=1;i<n+1;i++){
		cin>>a[i]>>f>>b[i];
	}
	for(int i=1;i<w+1;i++){
		int l=i;
		//cout <<l<<endl;
		for(int j=1;j<n+2;j++){
			if(l==a[j]){
				l=b[j];
				//cout<<a[j]<<" "<<l<<endl;
			}
			else if(l==b[j]){
				l=a[j];
				//cout<<b[j]<<" "<<l<<endl;
			}
			else if(j==n+1){
				last[l]=i;
				//cout <<last[l]<<" "<<l<<endl;
			}
		}
	}
	for(int i=1;i<w+1;i++){
		cout<<last[i]<<endl;
	}
}


Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int i = 0;
    for(i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
 
    for (i = n-1; i >= 0; i -= 2) {
      System.out.print(a[i] + " ");
    }
    if(i == -2) {
      for (i = 1; i < n; i += 2) {
        System.out.print(a[i] + " ");
      }
    }else if(i == -1) {
      for (i = 0; i < n; i += 2) {
        System.out.print(a[i] + " ");
      }
    }
    System.out.println();
  }
}

Measured memory_bytes: 90800
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


    int N; std::cin >> N;
    std::vector<int> p(N);
    rep(i, N)std::cin >> p[i];
    std::vector<int> sorted = p;
    std::sort(sorted.begin(), sorted.end());

    if(sorted == p){
        std::cout << "YES";
        return 0;
    }

    bool flag = false;

    rep(i, N){
        rep(j, N){
            if(i >= j)continue;
            std::vector<int> tmp = p;
            std::swap(tmp[i], tmp[j]);
            if(tmp == sorted){
                flag = true;
            }
        }
    }

    if(flag)std::cout << "YES";
    else std::cout << "NO";




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<string> S(N);
  for (int i=0; i<N; i++) {
    cin >> S.at(i);
  }
  
  int c0,c1,c2,c3;
  c0 = 0;
  c1 = 0;
  c2 = 0;
  c3 = 0;
  
  for (int i=0; i<N; i++) {
    if ( S.at(i) == "AC") {
      c0 = c0 + 1;
    }
    else if ( S.at(i) == "WA") {
      c1 = c1 + 1;
    }
    else if ( S.at(i) == "TLE") {
      c2 = c2 + 1;
    }
    else {
      c3 = c3 + 1;
    } 
  }
  
  cout << "AC" << " x " << c0 << endl;
  cout << "WA" << " x " << c1 << endl;
  cout << "TLE" << " x " << c2 << endl;
  cout << "RE" << " x " << c3 << endl;
    
}

Measured memory_bytes: 6372
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
double eps=1e-9;
int x[23];
int y[23];
double dist[23][23];
int n;
int solve(int a,int b,double s){
    if(a==(1<<n)-1)return 1;
    for(int i=0;i<n;i++){//枝切り
        if(a&(1<<i))continue;
        if(s+dist[b][i]+eps>dist[n+1][i])return 0;
    }
    for(int i=0;i<n;i++){
        if(a&(1<<i))continue;
        
        if(solve(a+(1<<i),i,s+dist[b][i]))return 1;
    }
    return 0;
}
int main(){
    int a,hx,hy,dx,dy;
    while(scanf("%d%d%d%d%d",&a,&hx,&hy,&dx,&dy),a){
        n=a;
        for(int i=0;i<a;i++)scanf("%d%d",x+i,y+i);
        x[a]=hx;x[a+1]=dx;
        y[a]=hy;y[a+1]=dy;
        for(int i=0;i<a+2;i++)for(int j=0;j<a+2;j++)
            dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        if(solve(0,a,0))printf("YES\n");
        else printf("NO\n");
    }
}



Measured memory_bytes: 2572
from collections import Counter as c
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
s = dict(c(A))
if len(s) > K:
	s_s = sorted(s.items(), key=lambda x: x[1])
	l = len(s)
	i = 0
	cnt = 0
	while l > K:
		l -= 1
		cnt += s_s[i][1]
		i += 1
	print(cnt)
else:
	print(0)

Measured memory_bytes: 39356