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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x) {
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y) {
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z) {
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar() {
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y) {
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y) {
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

const int mod = 998244353;

map<string, int> dp;

inline int DP(string s) {
	if(s == "") {
		return 1;
	}
	if(dp.find(s) != dp.end()) {
		return dp[s];
	}
	if(s == "0" || s == "1") {
		return dp[s] = (1 + (s == "1"));
	}
	int n = SZ(s);
	int ret = DP(s.substr(0, n - 1));
	if(s[n - 1] == '1') {
		(ret <<= 1) %= mod;
	}
	for (int len = 1; len * 2 <= n; ++len) {
		for (int i = 2; i * len <= n; ++i) {
			string t = "";
			for (int j = 0; j < len; ++j) {
				t += "1";
			}
			for (int j = 0; j < len; ++j) {
				for (int k = 0; k < i; ++k) {
					int pos = n - k * len - j - 1;
					if(s[pos] == '0') {
						t[len - j - 1] = '0';
						break;
					}
				}
			}
			ret = ((long long) DP(t) * DP(s.substr(0, n - len * i)) + ret) % mod;
		}
	}
	return dp[s] = ret;
}

int main() {
	string s;
#ifdef DEBUG
	srand(time(0));
	s = "";
	for (int i = 0; i < 100; ++i) {
		bool f = rand() & 1;
		s += (f ? '1' : '0');
	}
	cout<<s<<endl;
#else
	cin>>s;
#endif
	printf("%d\n", DP(s));
	return 0;
}

Measured memory_bytes: 7296
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())


Measured memory_bytes: 11160
# -*- coding: utf-8 -*-
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append((v,w))
    edge[v].append((u,w))

res = [-1]*n
res[0] = 0
q = [0]
while len(q)>0:
    u = q.pop(0)
    if len(edge[u])==0:
        continue

    for v,w in edge[u]:
        if res[v]!=-1:
            continue
        if w%2==0:
            res[v] = res[u]
        else:
            res[v] = (res[u]+1)%2
        q.append(v)

for r in res:
    print(r)


Measured memory_bytes: 38828
#include <stdio.h>

#define N 100001

void degree(int);
int depth(int);

struct Node {
  int parent;
  int left;
  int right;
};

struct Node nodes[N];
int counter = 0;

int main(void) {

  int i, j, n, m, new_node, child, left, right;

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    nodes[i].parent = -1;
    nodes[i].left = -1;
    nodes[i].right = -1;
  }

  for(i = 0; i < n; i++) {
    scanf("%d%d", &new_node, &m);

    for(j = 0; j < m; j++) {
      scanf("%d", &child);
 
      nodes[child].parent = new_node;

      if(j != 0) {
        nodes[left].right = child;
      } else {
        nodes[new_node].left = child;
      }

      left = child;

    }
  }

  for(i = 0; i < n; i++) {

    counter = 0;

    printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, depth(i));

    if(nodes[i].parent == -1) {
      printf("root, [");
    } else if (nodes[i].left == -1) {
      printf("leaf, [");
    } else {
      printf("internal node, [");
    }  

    counter = 0;
    degree(nodes[i].left);
    printf("]\n");
  }
  return 0;
}

int depth(int node_num) {

  if(nodes[node_num].parent == -1) {
    return counter;
  } else {
    counter++;
    return depth(nodes[node_num].parent);
  }

}

void degree(int node_num) {

  if(node_num != -1) {

    if(counter != 0) {
      printf(", ");
    }

    printf("%d", node_num);
    counter++;
    degree(nodes[node_num].right);
    
  }
}

Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;


int main()
{
    int n,m;

    while(scanf("%d%d",&n,&m) != EOF)
    {
        printf("%d\n",(n-1)*(m-1));
    }

    return 0;
}




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

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

  vector<int> a(n);
  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  //Setグループに代入して、元の配列との要素数を比較する
  set<int> s;
  rep(i,n) s.insert(a[i]);

  if (s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 10368
L, R = map(int, input().split())

min_mod = 2018
for l in range(L, R):
    for r in range(l+1, R+1):
        min_mod = min(min_mod, (l*r)%2019)
        if min_mod == 0:
            print(min_mod)
            exit()

print(min_mod)


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	ll N;
	cin>>N;
	for(ll i=3500;i>=1;i--) {
		for(ll j=3500;j>=1;j--) {
			w = ((ld)(N*i*j))/((4*i*j - N*i - N*j));
			if(w == (ll)(w) && w > 0) {
				cout<<i<<" "<<j<<" "<<(ll)w;newl;
				return;
			}
		}
 	}
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
 
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	FOR(i,0,5)cout<<s[i];
	cout << ' ';
	FOR(i,6,13)cout<<s[i];
	cout << ' ';
	FOR(i,14,19)cout<<s[i];
	cout << endl;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 + 7;
const int M = 100 * 1000 + 13;

int n, k;
int a[N];

bool read () {
	if (scanf("%d%d", &n, &k) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	return true;
}

int gr[M];

void solve() {
	set<int> mex;
	forn(i, N) mex.insert(i);
	
	gr[0] = 0;
	fore(i, 1, k + 1){
		vector<int> vals;
		forn(j, n) if (a[j] <= i && gr[i - a[j]] < N)
			vals.pb(gr[i - a[j]]);
		sort(all(vals));
		vals.resize(unique(all(vals)) - vals.begin());
		for (auto it : vals)
			mex.erase(it);
		gr[i] = *mex.begin();
		for (auto it : vals)
			mex.insert(it);
	}
	
	puts(gr[k] ? "First" : "Second");
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

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

int main()
{
    int n;
    cin >> n;
    int size = to_string(n).size();
    int ans = 0;

    for (auto k = 3; k <= size; k++)
    {
        for (auto mask = 0; mask < pow(3, k); mask++)
        {
            int tmp = mask;
            string s = "";
            bool three = false;
            bool five = false;
            bool seven = false;
            for (auto pos = 1; pos <= k; pos++)
            {
                int t = tmp % 3;

                if (t == 0)
                {
                    s = s + "3";
                    three = true;
                }
                else if (t == 1)
                {
                    s = s + "5";
                    five = true;
                }
                else
                {
                    s = s + "7";
                    seven = true;
                }
                tmp /= 3;
            }
            if(three && five && seven){
                if(n >= stoi(s)){
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int cost(vector<int> x, int target){
  if(x.size() == 0){
    return 0;
  }
  int s = 0;
  int cost = 10 * (x.size()-1);
  for(int i = 0; i < x.size(); i++){
    s += x[i];
  }
  if(target - s > 0){
    cost += target - s;
  } else { 
    cost += s - target;
  }
  return cost;
}

int dfs(int counter, vector<int> x, vector<int> y, vector<int> z, int A, int B, int C, vector<int > v){
  if(counter == v.size()){
    if(x.size()==0 || y.size()==0 || z.size() == 0){
      return 10000000;
    } else { 
      return(cost(x,A) + cost(y,B) + cost(z,C));
    }
  } else {
    vector<int> xn, yn, zn;
    xn = x; yn = y; zn = z;
    xn.push_back(v[counter]);
    yn.push_back(v[counter]);
    zn.push_back(v[counter]);
     
    counter++; 
    int tmp1 = dfs(counter, xn, y, z, A, B, C, v);
    int tmp2 = dfs(counter, x, yn, z, A, B, C, v);
    int tmp3 = dfs(counter, x, y, zn, A, B, C, v);
    int tmp4 = dfs(counter, x, y, z, A, B, C, v);
    return(min(min(tmp1,tmp2), min(tmp3,tmp4)));
  }

}

int main(){
  int N,A,B,C;
  cin >> N >> A >> B >> C;
  vector<int> v(N);
  
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  vector<int> x,y,z;
  cout << dfs(0, x,y,z, A, B, C, v) << endl;
}

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

# define All(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using ull = unsigned long long;
using ld  = long double;


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

    int n, x, y;
    cin >> n >> x >> y;


    vector <int> d(n);
    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {
            int k = min(j-i, abs(y-j) +abs(x-i)+1);
            k = min(k, abs(x-j)+abs(y-i)+1);

            d[k]++;
        }
    }

    for (int i=1; i<n; i++) {
        cout << d[i]<< endl;
    }

    return 0;
}


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Measured memory_bytes: 256
import numpy as np
a,b,x=map(int,input().split())
if x<=a*a*b/2:
  y=2*x/(a*b)
  print(360/((2*np.pi)/np.arctan(b/y)))
else:
  y=2*x/(a**2)-b
  print(360/((2*np.pi)/np.arctan((b-y)/a)))

Measured memory_bytes: 27104
local mmi, mma = math.min, math.max
local n = io.read("*n")

local used = {}
local len = {}
local cost = {}
for i = 1, n do
  for j = 1, n do
    local idx = (i - 1) * n + j
    local z = mmi(i - 1, j - 1, n - i, n - j)
    len[idx] = z
    cost[idx] = 1
  end
end

local ret = 0
-- local t = {}
local tasks = {}

for i = 1, n * n do
  -- t[i] = io.read("*n")
  local pos = io.read("*n")
  ret = ret + len[pos]
  cost[pos] = 0

  local done = 0
  local taskpos = 1
  tasks[1] = pos

  local function walk(src, dst)
    if len[src] + cost[src] < len[dst] then
      len[dst] = len[src] + cost[src]
      taskpos = taskpos + 1
      tasks[taskpos] = dst
    end
  end

  while done < taskpos do
    done = done + 1
    local idx = tasks[done]
    if n < idx then walk(idx, idx - n) end
    if idx <= (n - 1) * n then walk(idx, idx + n) end
    if idx % n ~= 0 then walk(idx, idx + 1) end
    if idx % n ~= 1 then walk(idx, idx - 1) end
  end
end
print(ret)


Measured memory_bytes: 16996
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

map<int,int> pf(int N){
    map<int,int> ret;
    for(int i=2;i*i<=N;i++){
        while(N%i==0){
            ret[i]++;
            N/=i;
        }
    }
    if(N!=1){ret[N]++;}
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,p;
    cin>>n>>p;
    map<int,int>mp = pf(p);
    int ans = 1;
    for(auto i:mp){
        ans*=(int)(pow(i.first,i.second/n));
    }
    cout<<ans<<endl;
}

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

int main(){
    int d,g;
    cin >> d >> g;
    int p[d],c[d];
    for(int i=0; i<d; i++){
        cin >> p[i] >> c[i];
    }
    int ans = 10000;
    for(int i=0; i<pow(2,d); i++){
        int s = 0;
        int t = 0;
        for(int j=d-1; j>=0; j--){
            if(i&(1<<j)){
                s += p[j]*100*(j+1) + c[j];
                t += p[j];
            }
        }
        for(int j=d-1; j>=0; j--){
            if(s >= g) break;
            if(!(i&(1<<j))){
                int r = min(p[j]-1,(g-s-1)/((j+1)*100)+1);
                s += r*(j+1)*100;
                t += r;
            }
        }
        if(s>=g) ans = min(ans,t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
 
using namespace std;
 
ll a,b,res;
 
int main() {
  //  ios_base::sync_with_stdio(0); cin.tie(0);
  //  freopen("in.txt","r",stdin);
    cin>>a>>b;
    int r;
    if (a==b) {
        cout<<1<<endl;
        return 0;
    }
   // cout<<a<<b<<endl;
    for (int t=61;t>=0;t--) {
        if (a>=(1ll<<t)) {
            a-=(1ll<<t);
            b-=(1ll<<t);
        }
        else if (b>=(1ll<<t)) {
            b-=(1ll<<t);
            r=t;
            break;
        }
    }
   // cout<<a<<" "<<b<<endl;
    int k;
    for (k=0;;k++) {
        //cout<<k<<endl;
        if ((1ll<<k) > b) break;
    }
   //cout<<k<<endl;
    res = (1ll<<r) - a;
    if ((1ll<<k) > a) res+=(1ll<<r);
    else res+=(1ll<<r) + (1ll<<k) - a;
    cout<<res<<endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9 + 7

c_table = [n] * max(a, b)

for i in range(1, len(c_table)):
    numer = n - i
    denom = i + 1
    c_table[i] = c_table[i-1] * numer * pow(denom, mod-2, mod) % mod

ans = pow(2, n, mod) - 1 - c_table[a-1] - c_table[b-1]
print(ans % mod)


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

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

    if(n == 1){
        cout << k << endl;
        return 0;
    }
    cout << k*(int)pow(k-1,n-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a, b, plus, min, kake, out;
    cin >> a >> b;
    
    plus = a + b;
    min = a-b;
    kake = a*b;
    out = max(plus, min);
    out = max(out, kake);
    cout << out << endl;
    
}


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

int main() {
	
	int n;
	cin >> n;
	vector<int> x(n),y(n),a(n);
	for(int i=0; i<n; i++) cin >> x.at(i) >> y.at(i);
	int j = 1;
	for(int i=0; i<n; i++) {
		a.at(i) = i;
		j *= (i+1);
	}
	double b=0;
	do{
		for(int i=0; i<n-1; i++){
			int c=a.at(i), d=a.at(i+1);
			int e=x.at(c), f=x.at(d), g=y.at(c), h=y.at(d);
			b += sqrt( (e-f)*(e-f) + (g-h)*(g-h) );
		}
	}while(next_permutation(a.begin(),a.end()));
	cout << fixed << setprecision(10);
	cout << b/j << endl;
	
}

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

using namespace std;

int main(){

	int n;
	cin >> n;
	if( n < 1000 ){
		cout << "ABC" << endl;
	}
	else{
		cout << "ABD" << endl;
	}

	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec A(N, 0);
  llvec B(N, 0);
  llvec C(N, 0);
  rep(i, N)cin >> A[i];
  rep(i, N)cin >> B[i];
  rep(i, N)cin >> C[i];

  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));

  ll ans = 0;
  rep(i, N){
    ll b = B[i];
    ll a_num = lower_bound(ALL(A), b) - A.begin();
    ll c_num = C.end() - upper_bound(ALL(C), b);
    ans += a_num * c_num;
  }

  cout << ans;
  
  return 0;
}


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

using namespace std;

int main()
{
	char s[10];
	cin >> s;
	if(s[0] == 'S')
		cout << "Cloudy" << endl;

	else if(s[0] == 'C')
		cout << "Rainy" << endl;

	else if(s[0] == 'R')
		cout << "Sunny" << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long A, B, C;
  cin >> A >> B >> C;
  
  if(C > A + B) {
    cout << A + B*2 + 1 << endl;
  } else {
    cout << B + C << endl; 
  }
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

struct UnionFind {
  vll par;
  vll wcnt;
  vll bcnt;
  ll cnt;
  UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) {
    for (ll i = 0; i < N; i++) {
      par[i] = i;
      ll w = (ll)mp[0].size();
      if (mp[i / w][i % w] == '.')
        wcnt[i] = 1;
      else
        bcnt[i] = 1;
    }
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll get_wcnt(ll x) { return wcnt[find(x)]; }
  ll get_bcnt(ll x) { return bcnt[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll sizex = wcnt[x] + bcnt[x];
    ll sizey = wcnt[y] + bcnt[y];
    if (sizex < sizey) swap(x, y);
    par[y] = x;
    wcnt[x] += wcnt[y];
    bcnt[x] += bcnt[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  if (x == 1)
    ans += 300000;
  else if (x == 2)
    ans += 200000;
  else if (x == 3)
    ans += 100000;

  if (y == 1)
    ans += 300000;
  else if (y == 2)
    ans += 200000;
  else if (y == 3)
    ans += 100000;

  if (x == 1 && y == 1) ans += 400000;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)


#define NMAX 200000
vector<int> b[NMAX];
int node[NMAX];
int parent[NMAX];
bool flag[NMAX];

void maketree(int c, int p)
{
    parent[c] = p;
    for( auto itr = b[c].begin(); itr != b[c].end(); itr++ )
    {
        if( *itr != p ) 
        {
            maketree(*itr, c);
        }
    }
}

int getvalue(int i)
{
    if( parent[i] < 0 ) return node[i];
    if( !flag[i] )
    {
        node[i] += getvalue(parent[i]);
        flag[i] = true;
    }
    return node[i];
}

int main()
{
    int n, q;
    cin >> n >> q;
    rep(i, n) 
    {
        node[i] = 0;
        flag[i] = false;
    }
    for(int i = 0; i < n - 1; i++ )
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        b[u].push_back(v);
        b[v].push_back(u);
    }
    rep(j, q)
    {
        int p, x; cin >> p >> x; p--;
        node[p] += x;
    }

    maketree(0, -1);

    rep(i, n)
    {
        cout << getvalue(i) << " ";
    }
}

Measured memory_bytes: 25620
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000000

int n,k;
int h[100005];
int dp[100005];

int solve1(int c)
{
    if(dp[c]!=-1)
        return dp[c];

    if(c==1)
        return dp[1]=0;

    dp[c] = 1e18;
    for(int i=1;i<=k;i++)
    {
        if(c-i >= 1)
            dp[c] = min( dp[c],solve1(c-i) + abs(h[c]-h[c-i]) );
    }

    return dp[c];
}

void solve(int t)
{
    cin >> n >> k;

    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
        dp[i] = -1;
    }

    solve1(n);

    cout << dp[n];

    //cout << "Case #" << t << ": " << ;
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;

int n, m, v, p;
vint a;

bool check(int i) {
    int x = a[i] + m;
    if (x < a[p-1]) return false;
    ll y = (ll)(v-((p-1)+(n-i-1)+1))*m;
    if (y <= 0) return true;
    for (int j = p-1; j <= i-1; j++) {
        y -= x - a[j];
    }
    if (y <= 0) return true;
    else return false;
}

int main() {
    cin >> n >> m >> v >> p;
    a.assign(n+1,-inf);
    rep(i,n) cin >> a[i];
    sort(rall(a));
    int l = 0, r = n;
    while (r-l > 1) {
        int mid = (r+l)/2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << l+1 << endl;
}

Measured memory_bytes: 3700
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    for b_idx in range(b):
        if a_idx == a_len or c <= a[a_idx]:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(sum(a))


Measured memory_bytes: 28384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int ans = 0;
		try (Scanner sc = new Scanner(System.in)) {
			while (true) {
				int a = sc.nextInt();
				String b = sc.next();
				int c = sc.nextInt();
				if(b.equals("+")) {
					ans = a + c;
				}else if(b.equals("-")) {
					ans = a - c;
				}else if(b.equals("*")) {
					ans = a * c;
				}else if(b.equals("/")) {
					ans = a / c;
				}else if(b.equals("?")) {
					break;
				}
				System.out.println(ans);
			}
		}
	}
}



Measured memory_bytes: 26196
#include<iostream>
#include<string>
using namespace std;
int main() {
  int x;
  string a;
  getline(cin,a);
  for( x=0; x<a.size(); x++){
    if( a[x] == 'a' && a[x+1] == 'p' && a[x+2] == 'p' && a[x+3] == 'l' && a[x+4] == 'e'){
      a[x] = 'p';
      a[x+1] = 'e';
      a[x+2] = 'a';
      a[x+3] = 'c';
      a[x+4] = 'h';
    }else if( a[x] == 'p' && a[x+1] == 'e' && a[x+2] == 'a' && a[x+3] == 'c' && a[x+4] == 'h'){
      a[x] = 'a';
      a[x+1] = 'p';
      a[x+2] = 'p';
      a[x+3] = 'l';
      a[x+4] = 'e';
    }
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x7ffffff;
const int mod = 1000000007;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	bool ok = true;
	if (a.back() < k) ok = false;
	int tmp = a.back();
	rep(i, n - 1) tmp = gcd(tmp, a[i]);
	if (k % tmp != 0) ok = false;
	if (ok) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 640
/*input
5 12
10 2 8 6 4

*/
#include <bits/stdc++.h>
#define ll long long int
#define lld long double
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll n,k;cin>>n>>k;
	vector<int> vec;
	ll ma=0;ll g=0;
	for(int i=0;i<n;i++){
		ll x;cin>>x;
		if(x==k){
			cout<<"POSSIBLE\n";return 0;
		}
		ma=max(x,ma);
		g=__gcd(x,g);
		vec.push_back(x);
	}
	if(k>ma){
		cout<<"IMPOSSIBLE\n";return 0;
	}
	if(k%g==0)
		cout<<"POSSIBLE\n";
	else
		cout<<"IMPOSSIBLE\n";
	return 0;
}

Measured memory_bytes: 892
// きりみんちゃんの配信からきました
// 左右をとる+-1のしゃくとり、左がマイナスかつ右がプラスの場合には「左に行った後折り返す」vs「右に行ったあと折り返す」が発生する
// ゼロ含む場合マジでなんなんだよ
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	includeZero := false
	zeroIdx := -1
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		a[i] = j
		if j == 0 {
			includeZero = true
			zeroIdx = i
		}
	}
	if includeZero && k == 1 {
		fmt.Println(0)
		return
	}
	if includeZero && n > 1 {
		if zeroIdx != 0 && zeroIdx != n-1 {
			if abs(a[zeroIdx-1]) < abs(a[zeroIdx+1]) {
				a[zeroIdx] = a[zeroIdx-1]
			} else {
				a[zeroIdx] = a[zeroIdx+1]
			}
			// a[zeroIdx] = min(a[zeroIdx-1], a[zeroIdx+1])
			// } else {
			// 	a[zeroIdx] = a[zeroIdx+1]
		}
	}
	ans := 10000000000000000
	r := 0
	tmp := 0
	for l := 0; l <= n-k; l++ {
		for r < n && r-l < k {
			tmp += a[r]
			r += 1
		}
		if a[r-1] <= 0 {
			tmp = a[l] * -1
		} else if a[l] >= 0 {
			tmp = a[r-1]
		} else if a[l] < 0 {
			tmp = min(a[l]*-2+a[r-1], a[r-1]*2+a[l]*-1)
			// tmp += a[r-1]
		} else if a[l] > 0 {
			tmp = a[r-1]
		}
		// fmt.Println(a[l:r], tmp)
		ans = min(ans, tmp)
		tmp -= a[l]
	}
	fmt.Println(ans)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

double l[25],a[25],b[25];

inline double dist(int f,int e){
	double sum=0.0;
	sum+=(l[f]-l[e])*(l[f]-l[e]);
	sum+=(a[f]-a[e])*(a[f]-a[e]);
	sum+=(b[f]-b[e])*(b[f]-b[e]);
	return sum;
}

int main(void){
	int n,m;
	cin >> n >> m;
	double ans=0.0;
	rep(i,n) cin >> l[i] >> a[i] >> b[i];
	rep(mask,1<<n){
		if(__builtin_popcount(mask)!=m)
			continue;

		double cur=0.0;
		rep(j,n)rep(k,n){
			if(j>=k)
				continue;
			if((~mask)&(1<<j))
				continue;
			if((~mask)&(1<<k))
				continue;
			cur+=dist(j,k);
		}
		ans=max(ans,cur);
	}
	cout.precision(9);
	cout << fixed << ans << endl;
	return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
int D;
int c[27], s[366][27];
int L[27];
long long ANS = 0;
long long ans = 0;
int main(){
    scanf("%d",&D);
    for (int i = 1; i <= 26; i++) scanf("%d",&c[i]);
    for (int i = 1; i <= D; i++){
        for (int j = 1; j <= 26; j++) scanf("%d",&s[i][j]);
    }
    for (int i = 1; i <= D; i++){
        int b1 = -1;
        long long ok = 0;
        for (int t = 1; t <= 26; t++){
            ans = ANS;
            ans += s[i][t];
            for (int j = 1; j <= 26; j++){
                if (j == t) continue;
                ans -= c[j]*(i-L[j]);
            }
            if (b1 == -1 || ans > ok){
                b1 = t;
                ok = ans;
            }
            //printf("for %d: %lld\n",t,ans);
        }
        printf("%d\n",b1);
        //printf("score %lld\n",ok);
        ANS = ok;
        L[b1] = i;
    }
}


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

using namespace std;
int n, w, h, x, y;
int dist(int x1, int y1, int x2, int y2){
    int res = 0;
    if(x1 < x2 && y1 < y2){
	res += min(x2 - x1, y2 - y1);
	x1 += res;
	y1 += res;
    }
    res += abs(x2 - x1) + abs(y2 - y1);
    return res;
}

int main(){
    cin >> w >> h >> n;
    int nowx, nowy;
    long long res = 0;
    cin >> nowx >> nowy;
    for(int i = 1;i < n;i++){
	cin >> x >> y;
	res += min(dist(nowx, nowy, x, y), dist(x, y, nowx, nowy));
	nowx = x;
	nowy = y;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w;
    while(cin >> w >> h, w){
        vector<vector<int>> G(h+2, vector<int>(w+2, 1));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> G[i+1][j+1];
            }
        }
        vector<vector<int>> dp(h+2, vector<int>(w+2, 0));
        for (int i = 0; i < w; ++i) {
            if(G[1][i+1] != 1) dp[1][i+1] = 1;
        }
        int ans = 0;
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                if(i == h) ans += dp[i][j];
                else if(G[i][j] == 0){
                    for (int k = -1; k <= 1; ++k) {
                        if(G[i+1][j+k] == 0) dp[i+1][j+k] += dp[i][j];
                        else if(G[i+1][j+k] == 2 && !k) dp[i+1][j] += dp[i][j];
                    }
                }else if(G[i][j] == 2){
                    if(i >= h-1) ans += dp[i][j];
                    else if(G[i+2][j] != 1) dp[i+2][j] += dp[i][j];
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    map<string, int> frq;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        frq[s]++;
    }
    int maxf = 0;
    for (auto x : frq)
    {
        int f = x.second;
        if (maxf < f)
            maxf = f;
    }
    for (auto iter = frq.begin(); iter != frq.end(); iter++)
    {
        if (iter->second == maxf)
        {
            cout << iter->first << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 100, MAXW = 100000;
ll N, W, w[MAXN], v[MAXN], dp[MAXW + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> W;
    for (int i = 0; i < N; i++)
        cin >> w[i] >> v[i];
    for (int i = 0; i < N; i++)
        for (int k = 0; k + w[i] <= W; k++)
            dp[k] = max(dp[k], v[i] + dp[k + w[i]]);
    cout << *max_element(dp, dp + W + 1) << endl;
}


Measured memory_bytes: 1024
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
	a = L[i]
	for j in range(i+1, N-1):
		b = L[j]
		if a == b:
			continue
		for k in range(j+1, N):
			c = L[k]
			if a == c or b == c:
				continue
			if abs(a-b) < c and c < a+b:
				ans += 1
print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if(n==25){
        cout << "Christmas" << endl;
    }
    else if(n==24){
        cout << "Christmas Eve" << endl;
    }
    else if(n==23){
        cout << "Christmas Eve Eve" << endl;
    }
    else if(n==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}


Measured memory_bytes: 256
import math

x = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while(1):
    if(is_prime(x)):
        print(x)
        exit()
    else:
        x+=1
    

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

using namespace std;
using ll = long long;

int n;
vector<ll> dp;
vector<vector<ll>> a;

int main(){
    cin>>n;
    a.resize(n, vector<ll>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>a[i][j];
        }
    }
    dp.resize(1 << n);
    for(int mask = 0; mask < (1 << n); mask++){
        for(int i = 0; i < n; i++){
            if((1 << i) & mask){
                for(int j = i + 1; j < n; j++){
                    if((1 << j) & mask){
                        dp[mask] += a[i][j];
                    }
                }
            }
        }
    }
    for(int mask = 0; mask < (1 << n); mask++){
        for(int submask = mask; submask > 0; submask = (submask - 1) & mask){
            dp[mask] = max(dp[mask], dp[submask] + dp[submask ^ mask]);
        }
    }
    ll res = dp[(1 << n) - 1];
    cout<<res<<endl;
    return 0;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int D;
int c[26] = {};
int s[365][26] = {};
int state[365] = {};
int last[26] = {};

int score(int day){
    rep(i, 26){
        last[i] = 0;
    }

    int result = 0;

    rep(i, day){
        result += s[i][state[i] - 1];
        last[state[i] - 1] = i + 1;

        rep(j, 26){
            result -= ((i + 1) - last[j]) * c[j];
        }
    }

    return result;
}

void solve(){

}

int main(){

    cin >> D;
    rep(i, 26){
        cin >> c[i];
    }
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }
    rep(i, D){
        cin >> state[i];
    }

    //solve();

    rep(i, D){
        cout << score(i + 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,q;
map<ll,ll> mp;

int main(){
	cin>>n;
	ll t=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		mp[x]++;
		t+=x;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		ll x,y;
		cin>>x>>y;
		ll z=mp[x];
		t+=z*(y-x);
		mp.erase(x);
		mp[y]+=z;
		cout<<t<<endl;
	}
}

Measured memory_bytes: 7528
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner Cf=new Scanner(System.in);
		short n=Cf.nextShort();
		short A=Cf.nextShort();
		short B=Cf.nextShort();
	
		short[] arrayx=new short[n];
		for(short i=0;i<n;i++) {
			arrayx[i]=Cf.nextShort();
			
		}
		
		//solve
		solve(A,B,arrayx);
		
	}
	
	
	public static void solve(short A,short B,short[] array){
		int x=0,y=0,z=0;
		for(short a=0;a<array.length;a++) {
			if(array[a]<=A) {
				x++;
			}
			else if(A<array[a] && array[a]<=B) {
				y++;
			}
			else if(array[a]>B) {
				z++;
			}
		}
		short[] xarr=new short[x];
		short[] yarr=new short[y];
		short[] zarr=new short[z];
		
		int answer=0;
		
		if(x <= y && x <= z) {
			answer=x;
		}
		else if( y<=x && y<=z) {
			answer=y;
		}
		else if( z<=x && z<=y) {
			answer=z;
		}
		System.out.println(answer);
		
		
	}
	


}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
 
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef vector< ll > vl;
 
 
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define edl '\n'
#define ll long long int
#define forn(i,n) for ( int i=0 ; i<n ; i++ )
#define fornl(i,n) for(ll i=0;i<n;i++)
#define forni(i,j,n) for ( int i=j ; i<n ; i++ )
#define filecode ifstream cin("input.txt");ofstream cout("output.txt");
#define IOFAST ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define setPrecision(n) cout << std::setprecision(n) << std::fixed;
#define MOD 998244353
#define PI 3.14159265
#define DEBUG 0
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
bool comp ( ii a, ii b ){ return (a.first==b.first)?a.second<b.second:a.first<b.first; }
ll modInverse(ll a) { ll m = MOD;ll y = 0, x = 1;while (a > 1) {ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0) x += MOD;return x; }

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3] and s[4]==s[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; 
  cin>>n;
  long long sum=0;
  for(int i=1; i<=n; ++i) 
   if(i%3>0&&i%5>0)
        sum+=i;
  cout<<sum << endl;;
  return 0;
}


Measured memory_bytes: 3600
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
template <typename T>
ll SIZEOF(T a){return (ll)a.size();}
ll xlcm(ll a, ll b){return (a/__gcd(a, b))*b;}

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


const int N = 100005;

void SOLVE(){
    inpv(a, 2);
    inpv(b, 2);
    ll ans = -1e18;
    for(auto i:a){
        for(auto j:b){
            ans = max(ans, i*j);
        }
    }
    cout << ans << endl;
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif

    ll TC = 1;
    // cin >> TC;
    for(ll tc1=1; tc1<=TC; tc1++){
        // cout << "Case #" << tc1 << ": ";
        SOLVE();
    }
    printclock;
}

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

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

  int N; cin >> N;
  string S; cin >> S;

  for (int i = 0; i < S.size(); i++) {
    ll t = S[i] - 'A';
    t = (t + N) % 26;
    S[i] = 'A' + t;
  }

  cout << S << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,min=4001,p[3],d[2],pd[6],cnt=0;
	for(i=0;i<3;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<2;i++){
		scanf("%d",&d[i]);
	}
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			pd[cnt]=p[i]+d[j]-50;
			cnt++;
		}
	}
	for(i=0;i<6;i++){
		if(pd[i]<min){
			min=pd[i];
		}
	}
	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int n,m,c;
int main(){
  cin >> n >> m >> c;
  int ans=0;
  int b[m];
  rep(i,m){
    cin >> b[i];
  }
  rep(i,n){
    int calc=0;
    rep(j,m){
      int a;
      cin>> a;
      calc += a*b[j]; 
    }
    calc += c;
    if(calc>0) ans++;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256