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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main() {
	int n;
	while (cin >> n, n) {
		int y; cin >> y;
		double ma = -1;
		int manum = -1;
		
		REP(i, n) {
			double b, r, t;
			scanf("%lf %lf %lf", &b, &r, &t);
			
			double now;
			if (t == 1) {
				now = 1 + y * (r / 100);
			}
			else {
				now = pow(1 + r / 100, y);
			}
			
			if (chmax(ma, now)) manum = b;
		}
		
		cout << manum << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
ll sm,a[1000];
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;
	cin >> n >> m;
	n%=m;
	cout<<min(abs(n-m),n)<<endl;
}

Measured memory_bytes: 256
def diff_number(runrun_num: int, master_num: int = 753) -> int:
    return abs(master_num - runrun_num)


def main():
    s = input()
    min_num = int(s[0:3])
    for i in range(3, len(s) + 1):
        runrun_num = int(s[(i - 3):i])

        if diff_number(runrun_num) < diff_number(min_num):
            min_num = runrun_num
    print(diff_number(min_num))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int maxId = -1, maxVol = -1;

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int id = int.Parse(input[0]);
                int vol = int.Parse(input[1]);

                if (vol > maxVol)
                {
                    maxVol = vol;
                    maxId = id;
                }
                else if (vol == maxVol)
                {
                    maxId = Math.Min(maxId, id);
                }
            }
            Console.WriteLine("{0} {1}", maxId, maxVol);
        }
    }
}

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

typedef long long LL;

const int N=10000000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m;

void into(){
  scanf("%d%d",&n,&m);
}

int inv[N+9],fac[N+9],ifac[N+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int Get_c(int n,int m){return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}

int ans;

void Get_ans(){
  for (int i=1;i<=m;++i)
	for (int j=1;j<=i;++j){
	  int a=j,b=max(m-i-1,0),c=n-m,t=mul(mul(Get_c(i,j),a),mul(fac[a+b+c],inv[a+c]));
	  i-j&1?ssub(ans,t):sadd(ans,t);
	}
}

void work(){
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using namespace std; 

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} 
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, k;
    cin >> n >> k;

    v_int a(n);
    cin >> a;

    ll ans = LINF;
    irep(i, (1<<n)) {
        int cnt = 0;
        irep(j, n) {
            if(i & (1<<j)) { cnt++; }
        }
        if(cnt == k) {
            ll prev = 0;
            ll sum = 0;
            irep(j, n) {
                if(i & (1<<j)) { 
                    if(prev >= a[j]) {
                        prev++;
                        sum += prev - a[j];
                    } else {
                        prev = a[j];
                    }
                } else {
                    prev = max(prev, (ll)a[j]);
                }
            }
            chmin(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/



Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


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

	ll r = 0, g = 0, b = 0;
	rep(i, n)
	{
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') {
			g++;
		}
		else {
			b++;
		}
	}

	ll ans = r * g * b;
	for (int i = 0; i < n; ++i)
	{
		for (int j = (i + 1); j < n; ++j)
		{
			if (s[i] == s[j]) continue;
			int k = 2 * j - i;
			if (k >= n || s[i] == s[k] || s[j] == s[k]) continue;
			ans--;
		}
	}

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

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    string a, b;
    int n;
    cin >> n;
    int ap, bp;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        if(a > b){
            ap += 3;
            continue;
        }
        if(a < b){
            bp += 3;
            continue;
        }
        if(a == b){
            ap++;
            bp++;
        }
    }
    cout << ap << ' ' << bp << endl;
}


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

int main(){
  vector<int> a(3);
  vector<int> b(3);
  vector<vector<int>> c(3,vector<int>(3));

  a[0] = 0;
  
  rep(i,3) rep(j,3){
    cin >> c[i][j];
  }

  rep(i,3){
    b[i] = c[0][i] - a[0];
  }

  a[1] = c[1][0] - b[0];
  a[2] = c[2][0] - b[0];

  rep(i,3) rep(j,3){
    if(a[i]+b[j]!=c[i][j]){
      printf("No");
      return 0;
    }
  }

  printf("Yes");

  return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007  

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B);
    vector<ll> res(Q);
    for(int i = 0; i < A; i++) cin >> s[i];
    for(int i = 0; i < B; i++) cin >> t[i];
    for(int i = 0; i < Q; i++){
        ll x;
        cin >> x;
        auto iter_s = upper_bound(s.begin(), s.end(), x);
        ll idx_s = iter_s - s.begin();
        auto iter_t = upper_bound(t.begin() , t.end(), x);
        ll idx_t = iter_t - t.begin();
        ll ans_1, ans_2, ans_3, ans_4;
        if(idx_s == A or idx_t == B) ans_1 = INF;
        else ans_1 = max(s[idx_s], t[idx_t]) - x;
        if(idx_s == A or idx_t == 0) ans_2 = INF;
        else ans_2 = s[idx_s] - t[idx_t - 1] + min(s[idx_s] - x, x - t[idx_t - 1]);
        if(idx_s == 0 or idx_t == B) ans_3 = INF;
        else ans_3 = t[idx_t] - s[idx_s - 1] + min(t[idx_t] - x, x - s[idx_s - 1]);
        if(idx_s == 0 or idx_t == 0) ans_4 = INF;
        else ans_4 = x - min(s[idx_s - 1], t[idx_t - 1]);
        ll ans = min({ans_1, ans_2, ans_3, ans_4});
        res[i] = ans;
    }
    for(int i = 0; i < Q; i++) cout << res[i] << endl;
}

Measured memory_bytes: 5636
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

int W, H;
struct edge {
	int d;    //x方向->0 y方向->1
	long long c;
};
vector<edge> edges;

int main() {
	cin >> W >> H;
	for (int p = 0; p < W; p++) {
		edge e;
		cin >> e.c;
		e.d = 0;
		edges.push_back(e);
	}
	for (int q = 0; q < H; q++) {
		edge e;
		cin >> e.c;
		e.d = 1;
		edges.push_back(e);
	}
	sort(edges.begin(), edges.end(), [](edge a, edge b) {
		return a.c < b.c;
	});
	int x = W+1, y = H+1;
	long long ans = 0;
	for (edge e : edges) {
		if (e.d == 0) {
			ans += y * e.c;
			x--;
		}
		else {
			ans += x * e.c;
			y--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  long long n, k;
  cin >> n >> k;

  vector<long long> a(n), d(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  for (int i = 0; i < n; ++i)
    cin >> d[i];

  sort(a.begin(), a.end());
  sort(d.begin(), d.end(), greater<long long>());

  auto check = [&](long long x) {
    long long ret = 0;
    for (int i = 0; i < n; ++i) {
      long long cur = x / d[i];
      ret += max(0ll, a[i] - cur);
    }
    return ret;
  };

  long long l = 0, r = 1e18;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid) <= k) r = mid;
    else l = mid + 1;
  }

  cout << r << '\n';
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


void solve()
{
	int n;
	cin>>n;
	vector<ll>a(n+1);
	rep(i,n+1)cin>>a[i];
	ll ans=0;
	vector<ll>b(n+1);
	b[n]=a[n];
	for(int i=n-1;i>=0;--i){
		b[i]=b[i+1]+a[i];
	}
	ll pre=1;
	rep(i,n+1){
		ll add=min(b[i],pre);
		if(add<a[i]){
			cout<<-1;
			return;
		}
		ans+=add;
		add-=a[i];
		pre=add*2;
	}
	cout<<ans;
}

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


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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())
    

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        const int N = 5009;
      
        ll dp[N][N];
        ll cycle[N];
        
        void solve(){
            cin >> n >> k;
            
            ll perm[n+1];
            ll values[n+1];
            for(int i=1; i <= n;i++){
                cin >> perm[i];
            }
            for(int i=1;i<= n; i++) cin >> values[i];
            
           /* ll t = LLONG_MIN;
            for(int i=1;i <= n ;i++){
                ll current = 0;
                int position = i;
                for(int j=1; j <= k; j++){
                    current += values[perm[position]];
                    position = perm[position];
                    cout << current << " : " << i << "-" << j << endl;
                    t = max(t, current); 
                }
                
            }
            cout << t << endl;
            */
            
            for(int i=1; i<= n; i++){
                ll current = 0;
                int position = i;
                for(int j=1; j<= n; j++){
                    current += values[perm[position]];
                    position = perm[position];
                    dp[i][j] = current;
                    if(position == i && !cycle[i]) cycle[i] = j;  
                }
                if(!cycle[i]) cycle[i] = n-1;
            }
            ll answer = LLONG_MIN;
            
            
            
            for(int i=1;i<=n;i++){
                ll moves = k/cycle[i];
                for(int j=1; j<=n;j++){
                    if(j <= k) answer = max(answer, dp[i][j]);
                    if(k%cycle[i] >= j ) answer = max(answer, moves*dp[i][cycle[i]] + dp[i][j]);
                    
                    if(moves > 0 && (moves-1)*cycle[i] + j <= k) answer = max(answer, (moves-1) * dp[i][cycle[i]] + dp[i][j]);
                }
            }
            cout << answer << endl;
            /*
            for(int i=0; i<=n;i++){
                for(int j=0;j<=n;j++){
                    cout << dp[j][i] << " ";
                }cout << endl;
            }*/

           // cout << dp[8][n]*5 + dp[8][8] << endl;
        

        }



        int main(){
            ios_base::sync_with_stdio(false);

            


            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 199440
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
const int L = 1<<22 + 5;
ll n;
ll a[22][22];
int dp[L];
ll getSetBits(ll mask)
{
	ll cnt=0;
	while(mask>0)
	{
		if(mask%2)cnt++;
		mask/=2;
	}
	return cnt;
}
ll fx(ll mask)
{
	ll idx = getSetBits(mask);
	if(idx == n)
	{
		if(mask == (1<<n) - 1)
			return dp[mask]=1;
		else
			return dp[mask]=0;
	}
	if(dp[mask] != -1)
		return dp[mask];
	ll su = 0;
	for(int i=0;i<n;i++)
	{
		if(mask&(1<<i))
			continue;
		if(a[idx][i])
		{
			if(dp[mask | (1<<i)] != -1)
				su = (su + dp[mask | (1<<i)])%mod;
			else
				su = (su + fx(mask | (1<<i)))%mod;
		}
	}
	return dp[mask] = su;
} 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	ll i,j;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	for(i=0;i<L;i++)
		dp[i]=-1;
	cout<<fx(0)<<nl;
	return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> save(M,vector<int>(2));
  vector<vector<int>> G(N);
  for (int i=0;i<M;i++){
    cin >> save[i][0] >> save[i][1];
    G[save[i][0]-1].push_back(save[i][1]);
  }
  map<int,int> m;
  for (int i=0;i<N;i++){
    if (G[i].size()>1){
      sort(G[i].begin(),G[i].end());
    }
    for (int j=0;j<G[i].size();j++){
      m[G[i][j]]=j+1;
    }
  }
  for (int i=0;i<M;i++){
    string x=to_string(save[i][0]),y=to_string(m[save[i][1]]);
    while (x.size()<6){
      x='0'+x;
    }
    while (y.size()<6){
      y='0'+y;
    }
    cout << x << y << endl;
  }
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

void suma(ll &a,ll b){
    a += b%MOD;
    if (a>=MOD) a-=MOD;
}

int main() {
    READ(0);
    int n,k;cin>>n>>k;
    vi a(n);
    vector<ll> low(2005,0);
    FOR(i,n) {
        cin>>a[i];
        ++low[a[i]+1];
    }
    for(int i=2;i<2005;++i) low[i] += low[i-1];
    ll kk= ((ll)k*(k-1)/2)%MOD;
    ll ret=0;
    FOR(i,n){
        suma(ret,kk*low[a[i]]);
    }
    FOR(i,n){
        for(int j=i+1;j<n;++j){
            if (a[i]>a[j]){
                suma(ret,k);
            }
        }
    }
    cout << ret;
    return 0;
}



Measured memory_bytes: 256
#ifndef _WIN32
#include<iostream>
#endif 
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
template<typename T> 
bool chmin(T &l, T r) {
	bool res = l > r;
	if (res) {
		l = r;
	}
	return res;
}
struct cww {
	cww() {
		cout << fixed;
		cout << setprecision(10);
	}
}star;

int main() {
	int D; double E;
	while (cin >> D >> E, D) {
		double res = 100;
		REP(i, D) {
			int j = D - i;
			double ans = abs(sqrt(i*i + j*j) - E);
			chmin(res, ans);


		}
		cout << res << endl;


	}

	return 0;
}

Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P; //cost to

#define max_V 100001
const int INF = 1 << 30;

vector<P> G[max_V];
bool used[max_V];

//出力：コスト
ll prim(){
  ll res = 0LL;
  priority_queue<P, vector<P>, greater<P>> que;

  //点0を集合Xに
  used[0] = true;
  for(int i = 0; i < (int)G[0].size(); i++){
    que.push(G[0][i]);
  }

  while(!que.empty()){
    P e = que.top();
    que.pop();
    int to = e.second;
    ll cost = e.first;

    if(!used[to]){
      used[to] = true;
      res += cost;
      for(int i = 0; i < (int)G[to].size(); i++){
        if(!used[G[to][i].second]){
          que.push(G[to][i]);
        }
      }
    }
  }

  return res;
}

int main(){
  int N,M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G[a].push_back(P(c, b));
    G[b].push_back(P(c, a));
  }

  fill(used, used + N, false);
  cout << prim() << endl;
  return 0;
}



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

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

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

	vector<int> A(N);

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

	vector<int> div(N);
	int j = 0;
	for (int i = 0; i < A.size() - 1; ++i) {
		div[j++] = A[i + 1] - A[i];
	}
	div[N - 1] = K - A[A.size() - 1] + A[0];

	int tmp = 0;
	int ans = 0;
	for (int i = 0; i < div.size(); ++i) {
		tmp = max(tmp, div[i]);
		ans += div[i];
	}

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


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

 int main() {
   int N;
   int p[30];
   cin >> N ;
   int res = 0;
   for (size_t i = 0; i < N; i++) {
     cin >> p[i];
   }
   for (int i = 1; i < N - 1; i++) {
     if (p[i-1] < p[i] && p[i] < p[i+1]) {
       res++;
     } else if ((p[i-1] > p[i] && p[i] > p[i+1])) {
       res++;
     }
   }
   cout << res << '\n';
 }


Measured memory_bytes: 256
#include<stdio.h>
 
struct dice
{
    int n[6] ; //number
};
struct dice dice1 ;
 
 
int east()
{
    int mem = 0 ;
    mem = dice1.n[0] ;
    dice1.n[0] = dice1.n[3] ;
    dice1.n[3] = dice1.n[5] ;
    dice1.n[5] = dice1.n[2] ;
    dice1.n[2] = mem ;
}
 
int west()
{
    int mem = 0 ;
    mem = dice1.n[0] ;
    dice1.n[0] = dice1.n[2] ;
    dice1.n[2] = dice1.n[5] ;
    dice1.n[5] = dice1.n[3] ;
    dice1.n[3] = mem ;
}
 
int south()
{
    int mem = 0 ;
    mem = dice1.n[0] ;
    dice1.n[0] = dice1.n[4] ;
    dice1.n[4] = dice1.n[5] ;
    dice1.n[5] = dice1.n[1] ;
    dice1.n[1] = mem ;
}
 
int north()
{
    int mem = 0 ;
    mem = dice1.n[0] ;
    dice1.n[0] = dice1.n[1] ;
    dice1.n[1] = dice1.n[5] ;
    dice1.n[5] = dice1.n[4] ;
    dice1.n[4] = mem ;
}

int rol()
{
    int mem = 0 ;
    mem = dice1.n[1] ;
    dice1.n[1] = dice1.n[3] ;
    dice1.n[3] = dice1.n[4] ;
    dice1.n[4] = dice1.n[2] ;
    dice1.n[2] = mem ;
}
 
int main()
{
    int i,j ;
    int cmp=0 ;
 
    int  q=0,ue,mae;
 
    for (i=0 ;i < 6 ;i++)
    {
        scanf("%d" ,&cmp) ;
 
        dice1.n[i] = cmp ;
 
    }
    scanf("%d" ,&q) ;

    for (i=0 ;i < q ;i++)
    {
        ue=0,mae=0;
        scanf("%d%d",&ue,&mae);
       
        for (j=0 ;j<4 ;j++ ){ 
                             if(dice1.n[0]==ue)break;
                             east() ;
                             }
        if(dice1.n[0]!=ue){
                   for (j=0 ;j<4 ;j++ ){ 
                             if(dice1.n[0]==ue)break;
                             south() ;
                                       }
                           }
        for (j=0 ;j<4 ;j++ ){ 
                             if(dice1.n[1]==mae)break;
                             rol() ;
                             }
        printf ("%d\n" ,dice1.n[2]) ;

    }
 
        return 0 ;
}




Measured memory_bytes: 2120
#include<cstdio>
#include<algorithm>
using namespace std;

struct segtree{
  int n;
  int data[262143];
  segtree(int _n){
    n = 1;
    while(n<_n) n *= 2;
    fill(data,data+2*n-1,0);
  }
  void add(int i,int x){
    i += n-2;
    data[i] += x;
    while(i>0){
      i = (i-1)/2;
      data[i] += x;
    }
  }
  int getSum(int s,int t){
    return getSum(s-1,t,0,0,n);
  }
  int getSum(int a,int b,int k,int l,int r){
    if(a<=l&&r<=b) return data[k];
    else if(a>=r||b<=l) return 0;
    else{
      int vl = getSum(a,b,2*k+1,l,(l+r)/2);
      int vr = getSum(a,b,2*k+2,(l+r)/2,r);
      return vl + vr;
    }
  }
};

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  segtree st(n);
  for(int i=0;i<q;i++){
    int cmd,x,y;
    scanf("%d%d%d",&cmd,&x,&y);
    if(cmd==0) st.add(x,y);
    else if(cmd==1) printf("%d\n",st.getSum(x,y));
  }
  return 0;
}

Measured memory_bytes: 3788
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec;
#define INF LLONG_MAX
 
#define PP pair<ll,ll>
#define int long long int
 
#define pb push_back
#define int ll
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
#define N 100005
#define MOD 1000000007

ld get(ll x,ll y,ll a,ll b)
{
      return sqrt(((x-a)*(x-a))+((y-b)*(y-b)));
}
      
signed main()
{
      ll n;
      cin>>n;
      string s="12345678";
      
      s=s.substr(0,n);
      
      ll a[n+1][2];
      
      for(int i=1;i<=n;i++)
            cin>>a[i][0]>>a[i][1];
      
      ld dis=0,cnt=0;
      do{
            cnt++;
            for(int i=1;i<n;i++)
                  dis+=get(a[s[i-1]-'0'][0],a[s[i-1]-'0'][1],a[s[i]-'0'][0],a[s[i]-'0'][1]);
      }while(next_permutation(s.begin(),s.end()));
      
      cout<<setprecision(15)<<dis/cnt<<"\n";
}

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

using namespace std;

const int mod = 10007;
const string ord = "JOI";
int dp[1010][1 << 3];

int main(void) {
  int n;
  string s;
  cin >> n >> s;

  for (int i = 0; i < n; i++) {
    int p = ord.find(s[i]);
    if (i == 0) {
      for (int j = 0; j < (1 << 3); j++) {
        if (!(j >> 0 & 1)) continue;
        if (!(j >> p & 1)) continue;
        dp[i + 1][j] = 1;
      }
    } else {
      for (int j = 0; j < (1 << 3); j++) {
        if (!(j >> p & 1)) continue;
        for (int k = 0; k < (1 << 3); k++) {
          if (!(j & k)) continue;
          dp[i + 1][j] += dp[i][k];
          dp[i + 1][j] %= mod;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << 3); i++) {
    ans += dp[n][i];
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3220
#include <iostream>
using namespace std;

int main()
{
    int a;
    int c = 0;
    cin>>a;
    int b;
    cin>>b;
    if (a>=13)
    {
        cout<<b;
    }
    else if (a>=6&&a<=12)
    {
        cout<<b/2;
    }
    else
    cout<<c;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    string s; cin >> s;
    vector<char> v(s.size());

    int index = 0;
    for (int i=0; i<s.size(); i++)
    {
        if (s[i]=='0') { v[index] = '0'; index++; }
        else if (s[i]=='1') { v[index] = '1'; index++; }
        else if (s[i]=='B'&&index>0) index--;
    }

    for (int i=0; i<index; i++)
    {
        cout << v[i];
    }

    cout << "\n";

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
    int N;
    string S[111];


    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> S[j];
    }

    int count = 0;

    for (int j = 0; j < N; ++j) {
        count += S[j] == "A" ? 1 : -1;
        if (count < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << (count == 0 ? "YES" : "NO") << endl;
    return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n;
    cin >> n;
    vector<i32> v;
    for (i32 i = 0; i < n; i++) {
        i32 a;
        cin >> a;
        auto itr = upper_bound(begin(v), end(v), a, greater<>());
        if (itr == end(v)) v.push_back(a);
        else *itr = a;
    }

    cout << v.size() << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int A;
	cin >> A;
	cout << A + A * A + A * A * A << "\n";
	return 0;
}


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

public class Problem_D
{
  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var primes = FindPrimesBy(55555);
    var ans = primes.Where(p => p % 5 == 1).Take(N).ToArray();
    Console.WriteLine($"{string.Join(" ", ans)}");
  }

  private static int[] FindPrimesBy(int n)
  {
    var sieve = new bool[n + 1];
    var primes = new List<int>();
    for (var i = 2; i <= n; i++)
    {
      if (!sieve[i])
      {
        primes.Add(i);
        for (var j = 1; i * j <= n; j++)
          sieve[i * j] = true;
      }
    }
    return primes.ToArray();
  }
}


Measured memory_bytes: 13368
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j;
  int u, k, v, c;
  scanf("%d", &n);

  int d[n];
  int M[n][n];
  int done[n];
  
  for(i=0;i<n;i++){
    d[i] = INFTY;
    done[i] = 0;
  }
  d[0] = 0;
  
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  while(1){
    int doneNode = -1;
    for ( i = 0; i < n; i++ ){
      if(done[i] || d[i] == INFTY)
        continue;
      if(doneNode == -1 || d[i] < d[doneNode])
        doneNode = i;
    }
    if (doneNode == -1)
      break;

    done[doneNode] = 1;
    for ( j = 0; j < n; j++ ){
      if(M[doneNode][j] < INFTY){
        if(d[j] > d[doneNode] + M[doneNode][j]){
          d[j] = d[doneNode] + M[doneNode][j];
        }
      }
    }
  }
  
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }

  return 0;
}

Measured memory_bytes: 640
n = int(input())
x = (1 + n) * n // 2
l = n // 3
x -= 3 * (1 + l) * l // 2
l = n // 5
x -= 5 * (1 + l) * l // 2
l = n // 15
x += 15 * (1 + l) * l // 2
print(x)

Measured memory_bytes: 9108
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main(){

  string n;
  cin >> n;

  if(n[0]=='9' || n[1]=='9'){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
	ll n; cin >> n;
    vector<int> v;
    for(int i=0; i<3*n; ++i){
        int a; cin >> a;
        v.push_back(a);
        
    }
    ll sum=0;
    sort(v.begin(), v.end());
    int head=3*n-1, tail=0;
    while(true){
        sum+=v[head-1];
        tail++; head-=2;
        if(tail>head) break;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3444
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if j == (N + 1 - i):
                continue
            ans.append((i, j))
else:
    for i in range(1, N):
        for j in range(i+1, N+1):
            if j == (N - i):
                continue
            ans.append((i, j))
print(len(ans))
for x in ans:
    print(*x)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
long long N;
vector<long long> a(3), b(3);
long long dp[30000000];
// dp[i]は持ってる資金(or どんぐり)
// maximixe sum of sei subject to objective
long long calc(vector<long long> sei, vector<long long> obj, long long M) {
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < sei.size(); i++) {
        for(int v = 0; v + sei[i] <= M; v++) {
            chmax(dp[v + sei[i]], dp[v] + obj[i]);
        }
    }
    long long res = M;
    for(int v = 0; v <= M; v++) {
        chmax(res, dp[v] + M - v);
    }
    return res;
}

long long solve() {
    //どんぐりN個まででどんぐり評価価格by bを最大にする
    long long tmp = calc(a, b, N);
    //どんぐりt評価価格tmp以下(bによる評価)でどんぐり評価価格 by　a
    long long res = calc(b, a, tmp);
    return res;
}
int main() {
    cin >> N;
    for(int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < 3; i++) {
        cin >> b[i];
    }
    cout << solve() << endl;
}

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

#define CLEAN 0
#define DIRTY 1
#define SIZE  1401
#define INITIAL_STACK_SIZE 10

int table[SIZE][SIZE] = {};
int board[SIZE][SIZE] = {};

typedef struct Rectangle {
  int height;
  int pos;
} Rectangle;

typedef struct _stack {
  int size;
  int max;
  Rectangle *stack;
} *Stack;

Stack stack_init() {
  Stack stack = (Stack)malloc(sizeof(struct _stack));
  stack->size = 0;
  stack->max = INITIAL_STACK_SIZE;
  stack->stack = (Rectangle *)malloc(sizeof(Rectangle)*INITIAL_STACK_SIZE);
  return stack;
}

Rectangle empty_rectangle() {
  return (Rectangle) {
    .height = 0,
    .pos = 0
  };
}

Rectangle top(Stack stack) {
  if (stack->size <= 0) {
    return empty_rectangle();
  } else 
    return stack->stack[stack->size-1];
}

Rectangle pop(Stack stack) {
  if (stack->size <= 0) {
    return empty_rectangle();
  } else
    return stack->stack[--(stack->size)];
}

Rectangle push(Rectangle item, Stack stack) {
  int i;
  if (stack->size < stack->max) {
    stack->stack[(stack->size)++] = item;
  } else {
    Rectangle *newStack = (Rectangle *)malloc(sizeof(int) * stack->max * 2);

    if (newStack == NULL) {
      perror("malloc failed.\n");
      exit(-1);
    }
     
    for (i=0; i<stack->size; i++)
      newStack[i] = stack->stack[i];

    newStack[stack->size++] = item;
    stack->max *= 2;
    free(stack->stack);
    stack->stack = newStack;
  }

  return item;
}

int empty(Stack stack) {
  return !stack->size;
}

void free_stack(Stack stack) {
  free(stack);
}

void create_table(int h, int w) {
  int i, j;

  for (i=0; i<w; i++)
    table[0][i] = (board[0][i] ? 0 : 1);
  
  for (i = 1; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (board[i][j] == CLEAN)
	table[i][j] = table[i-1][j] + 1;
      else
	table[i][j] = 0;
    }
  }
}

int rectangleAreaMaxRow(int row[],int w) {
  Stack s = stack_init();
  int i, max = 0;
  row[w] = DIRTY;

  for (i=0; i<=w; i++) {
    Rectangle r;
    r.height = row[i];
    r.pos = i;
    
    if (empty(s) || top(s).height < r.height) {
      push(r, s);
    } else {
      int target = i;
      while (!empty(s) && top(s).height >= r.height) {
	Rectangle pre = pop(s);
	int area = pre.height * (i-pre.pos);
	max = (area > max ? area : max);
	target = pre.pos;
      }
      r.pos = target;
      push(r, s);
    }
  }

  free_stack(s);
  return max;
}
  
int rectangleAreaMax(int h, int w)
{
  int i, max = 0, temp;
  for (i=0; i<h; i++) {
    temp = rectangleAreaMaxRow(table[i], w);
    max = (temp > max ? temp : max);
  }

  return max;
}

int main() {
  int i, j, h, w;

  scanf("%d %d", &h, &w);
  for (i=0; i<h; i++)
    for (j=0; j<w; j++)
      scanf("%d", &board[i][j]);

  create_table(h, w);
  
  printf("%d\n", rectangleAreaMax(h, w));
  
  return 0;
}

Measured memory_bytes: 16056
#include <iostream>
    #include <stdio.h>
    #include <string>
    #include <math.h>
    #include<algorithm>
    #include <numeric>
    #include <cstdlib>
    using namespace std;

    int main(){
      string a,b;
      cin >> a >> b;
      a=a+b;
      int x;
      x=atoi(a.c_str());
      bool flag=false;
      for(int i=0;i<3400;i++){
        if(x==i*i){
          flag=true;
        }
      }
      if(flag) cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}

Measured memory_bytes: 256
def Q(x):
    print("?",x,flush=True)
    return int(input())

x=Q("A")
if x==128:
    L=128
else:    
    y=Q("A"*x)
    z=Q("A"*(x+1))

    if z==y:
        L=x+1
    else:
        L=x

S=[chr(i) for i in range(48,58)]+[chr(i) for i in range(65,91)]+[chr(i) for i in range(97,123)]
K=[-1]*62

for i in range(62):
    K[i]=L-Q(S[i]*L)

import heapq
A=[(K[i],S[i]*K[i]) for i in range(62)]
heapq.heapify(A)

while len(A)>1:
    x,y=heapq.heappop(A)
    if x==0:
        continue
    z,w=heapq.heappop(A)

    ind=0
    for i in range(len(w)):
        while Q(y[:ind]+w[i]+y[ind:])>=L-x-i:
            ind+=1
        y=y[:ind]+w[i]+y[ind:]
        ind+=1
    heapq.heappush(A,(x+z,y))
    
print("!",A[0][1],flush=True)

Measured memory_bytes: 9320
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  string s;
  cin >>s;
  sort(s.begin(), s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout <<"Yes" <<endl;
  else cout <<"No" <<endl;
  return 0;
}


Measured memory_bytes: 256
n;
typedef struct{
	int x1,y1,x2,y2;
	char link[21];
}Btn;
typedef struct{
	char title[21];
	int bn;
	Btn btn[100];
}Page;
Page page[100];
hist[99999],hidx,hmax;
main(){
	int W,H,m,i,j;
	char op[9];
	for(;scanf("%d",&n)*n;){
		scanf("%d%d",&W,&H);
		for(i=n;i--;){
			Page*p=page+i;
			scanf("%s%d",p->title,&p->bn);
			for(j=p->bn;j--;){
				Btn*b=p->btn+j;
				scanf("%d%d%d%d%s",&b->x1,&b->y1,&b->x2,&b->y2,b->link);
			}
		}
		*hist=n-1;
		hmax=0;
		hidx=0;
		scanf("%d",&m);
		for(;m--;){
			scanf("%s",op);
			if(strcmp(op,"click")==0){
				Page*p=page+hist[hidx];
				int x,y;
				scanf("%d%d",&x,&y);
				for(i=p->bn;i--;){
					Btn*b=p->btn+i;
					if(x>=b->x1&&x<=b->x2&&y>=b->y1&&y<=b->y2){
						for(j=n;j--;){
							if(strcmp(page[j].title,b->link)==0){
								hist[hmax=++hidx]=j;
							}
						}
					}
				}
			}
			if(strcmp(op,"back")==0){
				if(hidx>0)
					hidx--;
			}
			if(strcmp(op,"forward")==0){
				if(hidx<hmax)
					hidx++;
			}
			if(strcmp(op,"show")==0){
				puts(page[hist[hidx]].title);
			}
		}
	}
}

Measured memory_bytes: 0
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ld;
int main() {
	int n,m;
	cin>>n>>m;
	int a[51];
	for(int i=0;i<=n;i++)
		a[i]=0;
	for(int i=0;i<m;i++){
		int b,c;
		cin>>b>>c;
		a[b]++;
		a[c]++;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<endl;
}

Measured memory_bytes: 256
import Data.Functor( (<$>))

main = do
    getLine
    values <- (read <$>) . words <$> getLine	::IO [Int]
    let
	bubbleSort (list,count)
	  = let
	    v@(scanResult, swapCount) = bubbleScan (reverse list) [] count
	      where
		bubbleScan [x] l count	    = (x:l, count)
		bubbleScan (x1:x2:xs) l count
		  |  x1 < x2		= bubbleScan (x1:xs) (x2:l) (count+1)
		  | otherwise		= bubbleScan (x2:xs) (x1:l) count
	  in
	    if count == swapCount
	    then v
	    else bubbleSort v

	(sorted, numSwap)  = bubbleSort (values, 0)

    putStrLn . unwords $ show <$> sorted
    print numSwap



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

int main(){
	
	int n;
	cin >> n;
	double x;
	vector<double> v;
	while (n--){
		cin >> x;
		v.push_back(x);
	}
	sort(v.rbegin(), v.rend());
	while((int) v.size() != 1){
		x = v.back()/2;
		v.pop_back();
		x += v.back()/2;
		v.pop_back();
		v.push_back(x);
	}
	cout << v.back(); 
		
		
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using    namespace std;
#define  ll        long long
#define  pb        push_back
#define  ff        first
#define  ss        second
#define  mk        make_pair
#define  all(v)    v.begin(),v.end()
#define  allr(v)   v.rbegin(),v.rend()
#define  sz        size()
#define  Tanmoy    ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0)

const int MOD=1e9+7;
/*
for(ll i=0; i<n; i++)      **I Want To Be The Best**
for(ll i=n-1; i>=0; i--)
*/

int main()
{
     Tanmoy;

     int n; cin>>n;
     cout<<(n<30 ? "No" : "Yes");

  return 0;
}





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

using namespace std;

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


const long inf=10000000000;

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

  long n,m;
  cin >> n >> m;
  vector<long> a(m),c(m,0);
   rep(i,0,m){
    cin >> a[i];
     long b;
     cin >> b;
     rep(j,0,b){
       long d;
       cin >> d;
       d--;
      c[i]+=(1<<d);
     }
   }
  
 vector<long> dp(1<<n,inf);
  dp[0]=0;
  rep(i,0,m){
    rep(j,0,(1<<n)){
    dp[(j|c[i])]=min({dp[(j|c[i])],dp[j]+a[i]});
    }
    }
  
  if(dp[((1<<n)-1)]==inf) cout << -1 << endl;
  else cout << dp[((1<<n)-1)] << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(input())
S=[]
for i in range(h):
    S.append([])
x=[-1,-1,-1,0,0,1,1,1]
y=[-1,0,1,-1,1,-1,0,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            t=0
            for k in range(8):
                if 0<=i+x[k]<h and 0<=j+y[k]<w and s[i+x[k]][j+y[k]]=="#":
                    t+=1
            T=str(t)
            S[i].append(T)
        else:
            S[i].append("#")
for i in range(h):
    print("".join(S[i]))

Measured memory_bytes: 70396
/*
* @FileName: D:\代码与算法\2017训练比赛\11.18-atcoder\a.cpp
* @Author: Pic
* @Created Time: 2017/11/18 19:49:23
*/
#include <bits/stdc++.h>
using namespace std;
int dis[13][13];
int mp[230][230];
void floyd()
{
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(dis[i][k]+dis[k][j]<dis[i][j]){
					dis[i][j]=dis[i][k]+dis[k][j];
				}
			}
		}
	}
}
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>dis[i][j];
		}
	}
	floyd();
	int x;
	int res=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>x;
			if(x!=-1&&x!=1){
				res+=dis[x][1];
			}
		}
	}
	cout<<res<<endl;
	
}


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

using namespace std;

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;

  int el;
  int maxx = -100;
  for (int i=0; i<n; ++i) {
    cin >> el;
    maxx = max(maxx,el);
  }
  int miny = 100;
  for (int i=0; i<m; ++i) {
    cin >> el;
    miny = min(miny,el);
  }
  
  for (int i=x+1; i<=y; ++i) {
    if (maxx<i && miny>=i) {
      cout << "No War" << endl;
      return 0;
    }
  }
  
  cout << "War" << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    ld n,k; cin >> n >> k;

    ld res=0.0;
    for(ld i=1; i<=n; i++){
        if(k/i<1) res+=1/n;
        else res+=1/n*powl(0.50,ceil(log2l(k/i)));
    }   
    //cout<<powl(0.50,ceil(log2l(10)));
    //cout<<powl(0.50,ceil(log2l(5000)))<<endl;
    //cout<<powl(0.50,ceil(log2l(5000)))<<endl;
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int x = b - a;
	if (a > 0)printf("Positive\n");
	else if (a <= 0 && b >= 0)printf("Zero\n");
	else {
		if (x % 2 == 0) printf("Negative\n");
		else printf("Positive\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k[15], s[15][15], p[15];
  for(int i=1; i<16; i++){
    for(int j=1; j<16; j++) s[i][j] = 0;
  }
  for(int i=1; i<m+1; i++){
    cin >> k[i];
    for(int j=1; j<k[i]+1; j++){
      int x;
      cin >> x; 
      s[i][x] = 1;
    }
  }
  //cout << s[2][1] << " " << s[2][2] << " " << s[2][3] <<  endl;
  for(int i=0; i<m; i++) cin >> p[i];
  int ans = 0;
  for(int bit=0; bit<(1<<n); bit++){
    vector<int> d(n);
    for(int i=0; i<n; i++){
      if(bit & (1<<i)){
        d[i] = 1;
      }
    }
    bool ok = true;
    for(int i=0; i<m; i++){
      int cnt = 0;
      for(int j=0; j<n; j++){
        if(d[j]==1 && s[i+1][j+1]==1) cnt++;
      }
      //cout << cnt << endl;
      if(cnt%2!=p[i]) ok = false;
    }
    if(ok) ans++;
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256