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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &V[i]);
  }

  ll ans = -LL_INF;
  rep(g_count, 1, N + 1) rep(r_count, 0, g_count + 1) {
    if (g_count + r_count > K) continue;

    rep(first, 0, g_count + 1) {
      multiset<ll> s;
      ll total = 0;
      rep(i, 0, first) {
        s.insert(V[i]);
        total += V[i];
      }

      rep(i, 0, g_count - first) {
        s.insert(V[N - 1 - i]);
        total += V[N - 1 - i];
      }

      auto start = begin(s);
      rep(j, 0, r_count) {
        total -= (*start);
        start++;
      }

      chmax(ans, total);
    }
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll num[11][11];
  vector<int> Ls(N+1,0);
  repp(x,1,N+1){
    int L = x;
    int X = x;
    while(X/10 != 0){
      X/=10;
      L = X;
    }
    Ls[x] = L;
  }

  repp(l,1,10)repp(r,1,10){
    num[l][r] = 0;
    repp(x,1,N+1){
      int R = x%10;
      int L = Ls[x];
      if( L == r && R == l)++num[l][r];
    }
  }

  ll ans = 0;
  repp(x,1,N+1){
    int R = x%10;
    int L = Ls[x];
    if(R==0)continue;
    ans += num[L][R];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;

#define forn(i,n) for(ll i = 0;i<n;i++)
#define forne(i,j,n) for(ll i = j;i<n;i++)
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ll INF = 1000000001;
const ll N = 100001;
const lld PI = 3.141593;
#define F first
#define pb(a) push_back(a)
#define S second
#define pii pair<int,int>
typedef pair<ll,ll> pll;

lld powm(ll base,ll exp) {
	ll ans=1;
	while(exp){
		if(exp&1) ans=(ans*base)%mod;
		exp>>=1,base=(base*base)%mod;
	}
	return ans;
}

// ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
// bool valid(ll i, ll j) {
// 	return i >= 1 && i <= n && j >= 1 && j <= m; 
// }
// int maxdepth = INT_MAX;
// vector<int> edgeVector[100000];
// ll minans = 1;
// printf("1 %d D\n",abs(r));
// priority_queue<ll,vector<ll>,greater<ll>> pq;
// ll a[N],b[N];
// vector<vector<ll>> adj(N);
// vector<set<ll>> adjs(N);
// ll adj[1001][1001];
// vector<vector<ll>> ans(1001);
// bool visited[N];
// ll cnt[1001];
// ll h,c,t;
// vector<pair<int, pair<int, int> > > g[300043];


int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll n;
cin>>n;
string s;
while(n>0){
	ll t = n%26ll;
	// cout<<t<<endl;
	n/=26ll;
	if(t > 0) s.pb('a'+t-1);
	else {
		s.pb('z');
		n--;
	}
}
reverse(s.begin(),s.end());
cout<<s<<endl;

}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
  int idx, val;
  double score;
  S(int i, int v, double s) :
    idx(i), val(v), score(s) {}
  bool operator < (const S& st) const {
    if(score != st.score) return score > st.score;
    if(idx != st.idx) return idx < st.idx;
    return val > st.val;
  }
};

int main(){
  int N;
  while(cin>>N && N){
    int a[20];
    REP(i, N) cin>>a[i];
    priority_queue<S> que;
    FOR(v, 1, 100001) que.push(S(1, v, (double)abs(a[0] - v) / a[0]));
    bool used[20][150001] = {};
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.idx == N){
        printf("%.12f\n", s.score);
        break;
      }
      if(used[s.idx][s.val]) continue;
      used[s.idx][s.val] = true;
      for(int k = 1; k * s.val <= 150000; k++){
        int nv = k * s.val;
        que.push(S(s.idx + 1, nv, max(s.score, (double)abs(a[s.idx] - nv) / a[s.idx])));
      }
    }
  }
  return 0;
}

Measured memory_bytes: 14052
n,m,c = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    a.append(tmp)

cnt = 0
for i in range(n):
    tmplst = [a[i][x] * b[x] for x in range(m)]
    if sum(tmplst) + c > 0:
        cnt += 1

print(cnt)

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353;

int sg[3][maxn],n,f[3][maxn],r[maxn],c[3][maxn];
vector<int > e[maxn];

int qpow(int a,int x) {
    int res=1;
    for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod;
    return res;
}

void update(int &x,int y) {x+=y;if(x>=mod) x-=mod;}

void solve(int t) {
    int m;read(m);
    for(int i=1;i<=n;i++) e[i].clear();
    for(int i=1,x,y;i<=m;i++) read(x),read(y),e[x].pb(y),e[y].pb(x);
    for(int i=n;i;i--) {
        for(auto v:e[i]) if(v>i) r[sg[t][v]]=1;
        int x=0;for(;r[x];x++);sg[t][i]=x;c[t][x]++;
        for(auto v:e[i]) r[sg[t][v]]=0;
        update(f[t][sg[t][i]],qpow(10,18*i));
    }
}

int main() {
    read(n);
    for(int i=0;i<=2;i++) solve(i);
    int ans=0;
    for(int i=0;c[0][i];i++)
        for(int j=0;c[1][j];j++) {
            int k=i^j;
            // printf("%d %d %d\n",f[0][i],f[1][j],f[2][k]);
            update(ans,1ll*f[0][i]*f[1][j]%mod*f[2][k]%mod);
        }
    write(ans);
    return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;
const ll INF = 1e11;

int a, b, q;
ll s[MAXN], t[MAXN], x[MAXN];

void solve() {
  for (int i=0;i<q;i++) {
    auto alow = upper_bound(s, s + a, x[i]) - 1;
    auto ahigh = upper_bound(s, s + a, x[i]);
    auto blow = upper_bound(t, t + b, x[i]) - 1;
    auto bhigh = upper_bound(t, t + b, x[i]);
    if (*alow == 0) {
      alow++;
    }
    if (*blow == 0) {
      blow++;
    }
    ll diff = INF;
    if (*alow <= x[i] && *blow <= x[i]) {
      diff = min(diff, abs(x[i] - min(*alow, *blow)));
    }
    if (*ahigh >=  x[i] && *bhigh >= x[i]) {
      diff = min(diff, abs(x[i] - max(*ahigh, *bhigh)));
    }
    if (*alow <= x[i] && x[i] <= *bhigh) {
      diff = min(diff, abs(x[i] - *alow) + abs(x[i] - *bhigh) + min(abs(x[i] - *alow), abs(x[i] - *bhigh)));
    }
    if (*blow <= x[i] && x[i] <= *ahigh) {
      diff = min(diff, abs(x[i] - *ahigh) + abs(x[i] - *blow) + min(abs(x[i] - *ahigh), abs(x[i] - *blow)));
    }
    cout << diff << endl;
  }
}

int main() {
  cin >> a >> b >> 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++) {
    cin >> x[i];
  }
  solve();
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/arc099/tasks/arc099_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll S(ll n){
    string str_n = to_string(n);
    return accumulate(str_n.begin(),str_n.end(),0LL) - '0'*str_n.length();
}
void solve(){
    ll K; cin >> K;
    ll snuke = 1, base = 1;
    for(ll i = 1; i <= K;i++){
        cout << snuke << endl;
        ll x = snuke + base, y = snuke + base*10;
        if(x*S(y) <= y*S(x)){
            snuke = x;
        }else{
            snuke = y;
            base*=10;
        }
    }
    return;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i,start,end) for(int i=start;i<=end;i++)  
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=1e3+5;

int a[N];

int main(){
    int n,ma=1,mi=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]<a[mi]) mi=i;
        if(a[i]>a[ma]) ma=i;
    }
	cout<<2*n-1<<endl;
    if(abs(a[ma])>=abs(a[mi])){
        for(int i=1;i<=n;i++){
            cout<<ma<<" "<<i<<endl;
        }
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }
    else{
        for(int i=1;i<=n;i++){
            cout<<mi<<" "<<i<<endl;
        }
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=2007,P=1000000007;
int n,m,A[N],B[N],F[N][N];
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%d",&A[i]);
	For(i,1,m) scanf("%d",&B[i]);
	For(i,1,n) F[i][0]=1;
	For(i,0,m) F[0][i]=1;
	For(i,1,n)
		For(j,1,m) {
			F[i][j]=(F[i-1][j]+F[i][j-1])%P;
			if(A[i]!=B[j]) F[i][j]=(F[i][j]-F[i-1][j-1]+P)%P;
		}
	printf("%d",F[n][m]);
	return 0;
}

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

#define MAXN 100005
#define ls x << 1
#define rs x << 1 | 1
#define INF 0x3f3f3f3f3f3f3f3f

typedef long long lint;

using namespace std;

int n, m, k; 
lint a[MAXN], suma[MAXN], b[MAXN], l[MAXN], r[MAXN], ele[MAXN << 1];
lint f[MAXN << 1];

struct segment {
	int l, r, v;
}t[MAXN << 3];

int read() {
	char c = getchar();
	int x = 0;
	while (!isdigit(c))
		c = getchar();
	while (isdigit(c)) {
		x = (x << 3) + (x << 1) + c - '0';
		c = getchar();
	}
	return x;
}

void build(int l = 1, int r = m, int x = 1) {
	t[x].l = l;
	t[x].r = r;
	t[x].v = 0;
	if (l == r)
		return ;
	int mid = (l + r) >> 1;
	build(l, mid, ls);
	build(mid + 1, r, rs);
}

void pushdown(int x) {
	if (t[x].v) {
		t[ls].v = t[rs].v = t[x].v;
		t[x].v = 0;
	}
}

void modify(int l, int r, int v, int x = 1) {
	if (l > r)
		return ;
	if (l <= t[x].l && t[x].r <= r) {
		t[x].v = v;
		return ;
	}
	pushdown(x);
	int mid = (t[x].l + t[x].r) >> 1;
	if (l <= mid)
		modify(l, r, v, ls);
	if (r > mid)
		modify(l, r, v, rs);
}

int query(int p, int x = 1) {
	if (t[x].l == t[x].r)
		return t[x].v;
	pushdown(x);
	int mid = (t[x].l + t[x].r) >> 1;
	if (p <= mid)
		return query(p, ls);
	return query(p, rs);
}

int dis(int x, int y) {
	return (ele[y] - ele[x] + k) % k;
}

int main() {
	// freopen("s.txt", "r", stdin);
	// freopen("a.out", "w", stdout);
	n = read();
	k = read();
	for (int i = 1; i <= n; ++i) {
		a[i] = read();
		b[i] = read();
		if (b[i] == 1 && a[i] * 2 > k) {
			puts("-1");
			return 0;
		}
		suma[i] = suma[i - 1] + a[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (b[i] == 1) {
			l[i] = (-suma[i - 1] * 2 % k + k) % k;
			r[i] = (-suma[i] * 2 % k + k) % k;
		}
		else {
			l[i] = 0;
			r[i] = k - 1;
		}
		ele[++m] = l[i];
		ele[++m] = r[i];
	}
	sort(ele + 1, ele + m + 1);
	m = unique(ele + 1, ele + m + 1) - ele - 1;
	build();
	for (int i = 1; i <= n; ++i) {
		l[i] = lower_bound(ele + 1, ele + m + 1, l[i]) - ele;
		r[i] = lower_bound(ele + 1, ele + m + 1, r[i]) - ele;
	}
	for (int i = n; i >= 1; --i) {
		int j = query(l[i]);
		if (!j)
			f[i] = 0;
		else 
			f[i] = f[j] + dis(l[i], l[j]);
		// cout << i << " " << f[i] << " " << l[i] << " " << r[i] << endl;
		if (l[i] <= r[i]) {
			modify(1, l[i] - 1, i);
			modify(r[i] + 1, m, i);
		}
		else 
			modify(r[i] + 1, l[i] - 1, i);
	}
	lint ans = f[1];
	for (int i = 1; i <= m; ++i) {
		int j = query(i);
		if (!j)
			ans = 0;
		ans = min(ans, f[j] + dis(i, l[j]));
	}
	printf("%lld\n", ans + suma[n] * 2);
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  ll x = 1;
  ll ans = LINF;
  while(x*x<=n){
    if(n%x==0){
      ans = x + n/x - 2;
    }
    x++;
  }
  cout << ans << endl;

}

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

namespace contest
{
    class Program
    {
        static int Main(string[] args)
        {
            int MAX = 200;

            char text_split = ' ';

            for (int i = 0; i < MAX; i++)
            {
                string read = Console.ReadLine();

                if (read == null) break;
                else
                {
                    string[] words = read.Split(text_split);

                    if( words[1] == null) break;
                    
                    int a_num = int.Parse(words[0]);
                    int b_num = int.Parse(words[1]);

                    //出力
                    int ab = a_num + b_num;
                    int count = 1;
                    while (ab >= 10)
                    {
                        ab /= 10;
                        count++;
                    }
                    Console.WriteLine("{0}", count);
                }
            }

            //Console.ReadKey();
            return 0;
        }

    }
}

Measured memory_bytes: 5632
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input()) - 1])

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

int main() {
	int A, B;
	cin >> A >> B;
	int ans;
	if (A >= 13) ans = B;
	if (A >= 6 && A <= 12) ans = B/2;
	if (A <= 5) ans = 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3536
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;

#define ll long long

ll aCb(ll a, ll b);
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;

    map<string, ll> S;
    for(ll i=0;i<N;i++){
        string str;
        cin >> str;
        std::sort(str.begin(), str.end());
        S[str]++;
    }

    ll count = 0;
    for(auto iter:S){
        ll tempCount = iter.second;
        if(tempCount > 1)count += aCb(tempCount, 2);
    }

    cout << count << endl;

    return 0;
}
ll aCb(ll a, ll b){
    return a * (a-1) / 2;
}

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

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if ((h == 0) && (w == 0)) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i + j) % 2 == 0) {
                    cout << "#";
                }
                else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3128
//方針変えたら(たぶん)自明で草
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int k, q;
int d[5000];

int solve(int n, int x, int m) {
	int i;
	
	int s = x % m, ng = 0;
	rep(i, k) {
		int e = d[i] % m;
		int cnt;
		if (e == 0) { e = m; }
		if (n - 2 - i < 0) { cnt = 0; }
		else { cnt = (n - 2 - i) / k + 1; }
		s += e * cnt;
	}
	ng += s / m;
	return n - 1 - ng;
}

signed main() {
	int i;
	int n, x, m;

	cin >> k >> q;
	rep(i, k) cin >> d[i];
	
	rep(i, q) {
		cin >> n >> x >> m;
		int ans = solve(n, x, m);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;
    bool a[105];
    memset(a,0,sizeof a);
    cin>>n>>m>>x;
    for(int i=0;i<m;i++){
        int b;
        cin>>b;
        a[b]=true;
    }
    int ans1=0,ans2=0;
    for(int i=x;i<=n;i++){
        if(a[i] == true){
            ans1++;
        }
    }
    for(int i=1;i<=x;i++){
        if(a[i] == true){
            ans2++;
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return(0);
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

struct Parser {
  string s;
  int i;
  ll parse(const string &_s) {
    s = _s;
    i = 0;
    ll p = p_or();
    if (i != s.size()) throw 0;
    return p;
  }
  ll p_or() {
    ll p = p_xor();
    while(s[i]=='|') {
      i++;
      ll t = p_xor();
      p |= t;
    }
    return p;
  }
  ll p_xor() {
    ll p = p_and();
    while(s[i]=='^') {
      i++;
      ll t = p_and();
      p ^= t;
    }
    return p;    
  }
  ll p_and() {
    ll p = p_addsub();
    while(s[i]=='&') {
      i++;
      ll t = p_addsub();
      p &= t;
    }
    return p;    
  }
  ll p_addsub() {
    ll p = p_mul();
    while(s[i]=='+' || s[i]=='-') {
      char c = s[i++];
      ll t = p_mul();
      if (c =='+') {
        p += t;
      }else {
        p -= t;
      }
    }
    return p;  
  }
  ll p_mul() {
    ll p = p_numpar();
    while(s[i]=='*') {
      i++;
      ll t = p_numpar();
      p *= t;
    }
    return p;    
  }
  ll p_numpar() {
    if (s[i] == '(') {
      i++;
      ll p = p_or();
      if (s[i++] != ')') {
        throw 0;
      }
      return p;
    } else if (isdigit(s[i])) {
      if (s[i] == '0') throw 0;
      ll p = 0;
      while(isdigit(s[i])) {
        p = p*10 + s[i]-'0';
        i++;
      }
      return p;
    } else throw 0;
  }
} parser;

const string str = "*+-&^|0123456789";
ll INFLL = 1LL<<61;
map<pair<string, bool>, ll> mp;
ll solve(const string &s, int cnt, bool f=0) {
  if (mp.count(make_pair(s, f))) return mp[make_pair(s,f)];
  if (cnt == 0) {
    ll p = parser.parse(s);
    // cout << s << " " << p << endl;
    return mp[make_pair(s,f)] = p;
  }
  ll res = -INFLL;
  if (f) res = INFLL;
  // insert
  for (int i=0; i<=s.size(); ++i) {
    FOR(it, str) {
      string nxt = s.substr(0,i) + *it + s.substr(i);
      try {
        parser.parse(nxt);
        ll p = solve(nxt, cnt-1, !f);
        if (f) chmin(res, p);
        else chmax(res, p);
      } catch(int x) {
      }
    }
  }
  // delete
  REP(i,s.size()) {
    string nxt = s.substr(0,i) + s.substr(i+1);
    try {
      parser.parse(nxt);
      ll p = solve(nxt, cnt-1, !f);
      if (f) chmin(res, p);
      else chmax(res, p);
    } catch(int x) {
    }
  }
  return mp[make_pair(s,f)] = res;
}

int main() {
  int n;
  string s;
  while(cin >> n >> s, n) {
    mp.clear();
    n = ((n-1)&1)+1;
    cout << solve(s,n) << endl;
  }
}

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

bool isEven(int a) {
  return a % 2 == 0 ? true : false;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int &x : A)
    cin >> x;

  int num = -1;
  bool flag = true;
  while (flag) {
    num++;
    for (int &x : A) {
      if (isEven(x)) {
        x /= 2;
      }
      else {
        flag = false;
        break;
      }
    }
  }

  cout << num << endl;
}


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

int idx;
string s;

string cipher(){
  if(s.size() <= idx) return "";

  string res = "";

  while(idx < s.size() && s[idx] != ']'){
    if(s[idx] == '['){
      idx++;
      string tmp = cipher();
      reverse(tmp.begin(), tmp.end());
      res += tmp;
      idx++;
    }
    else{
      int add = 0;
      while(s[idx] == '+' || s[idx] == '-'){
        if(s[idx] == '+') add = (add + 1) % 26;
        else              add = (add + 25) % 26;
        idx++;
      }
      if(s[idx] == '?')
        res += '?';
      else
        res += (char)((s[idx] - 'A' + add) % 26) + 'A';
      idx++;
    }
  }

  return res;
}

int main(){
  while(cin >> s, s != "."){
    idx = 0;
    string ts = cipher();

    for(int i = 0; i < ts.size(); i++){
      if(ts[i] == '?'){
        cout << 'A';
      }
      else{
        cout << ts[i];
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MAXN 100000
#define ll long long
using namespace std;

ll v[55];
ll binomial[555][555];

int main() {
    for(int i=0;i<555;i++)
        for(int j=0;j<=i;j++) {
            if (j==0) {
                binomial[i][j]=1;
            } else {
                binomial[i][j]=binomial[i-1][j]+binomial[i-1][j-1];
            }
        }
    
    int N,A,B;
    cin>>N>>A>>B;
    for(int i=0;i<N;i++)
        cin>>v[i];
    sort(v,v+N);
    
    ll summ = 0;
    int first = N-A;
    vector<int> num_items;
    num_items.push_back(A);
    while (first-1 >= N-B && v[N-1]==v[first-1]) {
        first--;
        num_items.push_back(N-first);
        
    }
    
    
    
    for(int j=N-1;j>=first;j--) {
        summ += v[j];
    }
    
    
    printf("%lf\n",(double)summ / (double)(N-first));
    // avg = summ / (N-first+1);
    
    // 10,10,10,20.
    ll ans = 0;
    for(int k=0;k<num_items.size();k++) {
        // N-num_items[k] to N-1.
        
        
        int st = N-num_items[k];
        
        
        int en=st;
        while(en+1<N && v[en+1]==v[st])
            en++;
        // st to en
        int ct=0;
        for(int i=0;i<N;i++)
            ct += (v[i]==v[st]);
        
        ans += binomial[ct][en-st+1];
        
        
    }
    
    
    cout << ans << endl;
}

Measured memory_bytes: 2688
n = gets.chomp.to_i
txy_arr = []
n.times do |i|
  txy_arr << gets.chomp.split(" ").map(&:to_i)
end

pos_x = 0
pos_y = 0
now_t = 0
txy_arr.each do |(t, x, y)|
  dist = (x - pos_x).abs + (y - pos_y).abs
  time = t - now_t
  if time < dist || (time - dist) % 2 == 1 then
    puts 'No'
    exit
  end
  pos_x = x
  pos_y = y
  now_t = t
end

puts 'Yes'


Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
//#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);

int n;


int main(){
    cin >> n;
    vec(a,n);
    input(a,n);
    cin >> n;
    int ans = 0;
    REP(i,n){
        int m;
        cin >> m;
        int tmp = lower_bound(All(a),m) - a.begin();
        if(a[tmp] == m) ans++;
    }
    print(ans);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}




Measured memory_bytes: 3100
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort()
Q.sort()
cand = P[-X:] + Q[-Y:] + R
cand.sort()
print(sum(cand[-(X + Y):]))


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

using namespace std;

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

	char temp = s[0];
	int ans = 0;
	for (int i = 1;i < N;++i) {
		if (temp != s[i]) {
			++ans;
			temp = s[i];
		}
	}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {

string N,M,ans;  
int num ,sum;
cin >> N;
  sum = 0;
  num = N.size();
for(int i=0; i< num;i++){
  M = N.at(i);
  sum += stoi(M);
}
 if(sum % 9 == 0){
 ans = "Yes" ;
 } else{
 ans = "No";
 }
cout << ans << endl;
}

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    int L,R;
    cin >> L>>R;

    int r=2020;
    for (int64_t i=L;i<R && i<L+2019;++i) {
        for (int64_t j=i+1;j<=R&&j<i+1+2019;++j) {
            r = min<int>(r, (i*j)%2019);
        }
    }

    cout << r << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))

data.sort()
#print(data)
cost = 0
lost = M
for c in data:
    if lost != 0:
        if lost >= c[1]:
            lost -= c[1]
            cost += c[0] * c[1]
        else:
            cost += c[0] * lost
            lost = 0
    else:
        break
print(cost)

Measured memory_bytes: 27760
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int NMax = 200005;
int N;
queue <int> Q;
vector <int> G[NMax];
int Dist[NMax];
void Read(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
}

void BFS(int start){
    for(int i = 1; i <= N; i++)
        Dist[i] = -1;
    Dist[start] = 0;
    Q.push(start);
    while(!Q.empty()){
        int node = Q.front();
        Q.pop();
        for(int i = 0; i < G[node].size(); i++){
            int neighb = G[node][i];
            if(Dist[neighb] != -1)
                continue;
            Dist[neighb] = Dist[node] + 1;
            Q.push(neighb);
        }
    }
}

int findMaxDistanceNode(){
    int ans = 1, Max = Dist[1];
    for(int i = 2; i <= N; i++){
        if(Dist[i] > Max){
            Max = Dist[i];
            ans = i;
        }
    }
    return ans;
}

int findDiameter(){
    BFS(1);
    int newStart = findMaxDistanceNode();
    BFS(newStart);
    return Dist[findMaxDistanceNode()];
}

void Solve(){
    int diameter = findDiameter();
    if(diameter % 3 == 1)
        cout << "Second\n";
    else
        cout << "First\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 13556
#include<iostream>
using namespace std;
#define MAX_INT 1000
struct Card
{
    char mark;
    char num;
};

bool isStable(Card*in,Card*res,int N)
{
    for(int i=0; i< N; ++i)
    {
        if(in[i].mark!=res[i].mark)
        {
            return false;
        }
    }
    return true;
}

bool bubbleSort(Card*A,int N,Card* B)
{
    bool flg =true;
    while(flg)
    {
        flg =false;
        for(int j=N-1;j>0;--j)
        {
            if(B[j].num < B[j-1].num)
            {
                Card tmp;
                tmp = B[j-1];
                B[j-1] = B[j];
                B[j]=tmp;
                flg =true;
            }
        }
    }
    for(int k=0;k<N;k++)
    {
        if(k<N-1) cout << B[k].mark << B[k].num << " ";
        if(k==N-1) cout<< B[k].mark<<B[k].num<<endl;
    }
    
    return true;
}

bool selectionSort(Card*A,int N,Card*B)
{
    for(int i=0;i<N;++i)
    {
        int minj =i;
        for(int j=i;j<N;++j)
        {
            if(A[j].num<A[minj].num)
            {
                minj = j;
            }
        }
        if(minj !=i)
        {
            Card tmp;
            tmp = A[i];
            A[i] =A[minj];
            A[minj]=tmp;
        }
    }
    for(int k=0;k<N;k++)
    {
        if(k<N-1) cout << A[k].mark<<A[k].num << " ";
        if(k==N-1) cout<< A[k].mark<<A[k].num<<endl;
    }
    return isStable(A,B,N);
}


int main()
{
    int N;cin >>N;
    Card A[N],B[N],C[N];
    for(int i=0;i<N;++i)
    {
        cin>>A[i].mark>>A[i].num;
        B[i]=A[i];
        C[i]=A[i];
    }
    if(bubbleSort(A,N,B))
    {
        cout << "Stable" <<endl;
    }
    else
    {
        cout << "Not stable"<<endl;
    }
    
    if(selectionSort(C,N,B))
    {
        cout << "Stable" <<endl;
    }
    else
    {
        cout << "Not stable"<<endl;
    }
    
    
}


Measured memory_bytes: 3124
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int x;
    cin>>x;
    FOR(k,1,10000){
        if((x*k)%360==0){
            cout<<k<<endl;
            return 0;
        }
    }
}


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

using ll = long long;

const int MAXN = 4e5;
int N;
int A[MAXN];

ll maxSum[2][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < 3 * N; i++) {
		cin >> A[i];
	}

	for (int z = 0; z < 2; z++) {
		multiset<int> s;
		ll curSum = 0;
		for (int i = 0; i < 3 * N; i++) {
			s.insert(A[i]);
			curSum += A[i];
			if (int(s.size()) > N) {
				curSum -= *s.begin(); 
				s.erase(s.begin());
			}
			assert(int(s.size()) <= N);
			maxSum[z][i+1] = curSum;
		}
		reverse(A, A + 3 * N);
		for (int i = 0; i < 3 * N; i++) {
			A[i] *= -1;
		}
	}

	ll ans = -9e18;
	for (int i = N; i <= 2 * N; i++) {
		ans = max(ans, maxSum[0][i] + maxSum[1][3 * N - i]);
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#define NDEBUG

std::vector<int> next(std::vector<int> v) {
	std::vector<int> vec(v.size() + 1);
	for(int i = 0; i < (int)v.size(); i++) {
		int L = std::max(0, i - v[i]);
		int R = std::min((int)v.size() - 1, i + v[i]);

		vec[L]++;
		vec[R + 1]--;
	}
	for(int i = 0; i < (int)v.size() - 1; i++) vec[i + 1] += vec[i];
	vec.pop_back();
	return vec;
};

int main() {
	int n, k; scanf("%d%d", &n, &k); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	#ifndef NDEBUG
	cout << 0 << ": ";
	for(auto v: a) cout << v << " "; cout << endl;
	
	for(int i = 0; i < k; i++) {
		a = next(a);
		
		cout << i + 1 << ": ";
		for(auto v: a) cout << v << " "; cout << endl;
	}
	#endif

	for(int i = 0; i < k; i++) {
		auto v = next(a);

		if(v == a) break;
		a.swap(v);
	}

	for(auto v: a) cout << v << " "; cout << endl;
	return 0;
}


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;

int main()
{
	string s;
	cin >> s;
	n = s.size();
	rep(i,0,n-1){
		if(s[i] == s[i+1]){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
	}
	rep(i,0,n-2){
		if(s[i] == s[i+2]){
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair <int, int> pii;

const int INF=0x3f3f3f3f;
const int N=2e5+500;

int n, nep;
int par[N], p[N];
char str[N];
vector <int> v[30];
ll F[N];

void update(int pos, ll val) {
    for (; pos<=n; pos+=pos&-pos) {
        F[pos]+=val;
    }
}

ll query(int pos) {
    ll res=0;
    for (; pos>0; pos-=pos&-pos) {
        res+=F[pos];
    }
    return res;
}

int main() {
    scanf("%s", str);
    n=strlen(str);
    for (int i=0; i<n; ++i) {
        v[str[i]-'a'].push_back(i);
    }
    for (int i=0; i<26; ++i) {
        int l=0, r=v[i].size()-1;
        while (l<r) {
            par[v[i][l]]=v[i][r];
            par[v[i][r]]=v[i][l];
            l++;
            r--;
        }
        if (l==r) {
            ++nep;
            par[v[i][l]]=v[i][l];
        }
    }
    if (nep>1) {
        printf("-1");
        return 0;
    }
    memset(p, -1, sizeof p);
    int l=1, r=n;
    for (int i=0; i<n; ++i) {
        if (p[i]!=-1) continue;
        if (par[i]==i) {
            p[i]=n/2+1;
            continue;
        }
        p[i]=l;
        p[par[i]]=r;
        l++;
        r--;
    }
    ll sol=0;
    for (int i=0; i<n; ++i) {
            //printf("%d ", p[i]);
        sol+=(ll)i-query(p[i]);
        //printf("p[i]: %d, %lld\n", p[i], (ll)query(p[i]));
        update(p[i], 1LL);
    }
    printf("%lld", sol);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

int h,w,n;
string s[55];
ll c[55][55][3]; // 0 using / 1 on / 2 off
ll vi[1111],vj[1111];
ll dist[55][55];
vector<ll> t[55][55];
ll dp[1010][2];

int dd[]={-1,0,1,0,-1};

void dfs(int i,int j,int prei,int prej,ll sum,ll dst[55][55]){
  dst[i][j]=sum;
  rep(d,4){
    int ni=i+dd[d],nj=j+dd[d+1];
    if(ni==prei&&nj==prej)continue;
    if(ni>=0&&ni<h&&nj>=0&&nj<w&&s[ni][nj]!='#')dfs(ni,nj,i,j,sum+1,dst);
  }
}

int main(){
	cin.sync_with_stdio(false);
  cin>>h>>w>>n;
  rep(i,h)cin>>s[i];
  rep(k,3)rep(i,h)rep(j,w)cin>>c[i][j][k];
  rep(i,n)cin>>vi[i]>>vj[i];
  ll nt=0;
  t[vi[0]][vj[0]].push_back(0);
  rep(i,n-1){
    memset(dist,0,sizeof(dist));
    dfs(vi[i],vj[i],-1,-1,0,dist);
    ll ni=vi[i+1],nj=vj[i+1];
    while(dist[ni][nj]!=0){
      t[ni][nj].push_back(nt+dist[ni][nj]);
      rep(d,4){
        int nni=ni+dd[d],nnj=nj+dd[d+1];
        if(ni>=0&&ni<h&&nj>=0&&nj<w&&dist[nni][nnj]+1==dist[ni][nj]){
          ni=nni; nj=nnj;
          break;
        }
      }
    }
    nt+=dist[vi[i+1]][vj[i+1]];
  }
  ll res=0;
  rep(i,h)rep(j,w){
    if(t[i][j].size()==0)continue;
    rep(k,1010)rep(l,2)dp[k][l]=INF;
    dp[1][0]=c[i][j][1]+c[i][j][2];
    dp[1][1]=c[i][j][1];
    ll m=t[i][j].size();
    repl(k,1,m)rep(l,2){
      if(dp[k][l]==INF)continue;
      ll pt=t[i][j][k]-t[i][j][k-1];
      if(l==0){
        minch(dp[k+1][0],dp[k][l]+c[i][j][1]+c[i][j][2]);
        minch(dp[k+1][1],dp[k][l]+c[i][j][1]);
      }else{
        minch(dp[k+1][0],dp[k][l]+c[i][j][2]+pt*c[i][j][0]);
        minch(dp[k+1][1],dp[k][l]+pt*c[i][j][0]);
      }
    }
    //dbg(dp[m][0]);
    res+=dp[m][0];
  }
  cout<<res<<endl;
	return 0; 
}

Measured memory_bytes: 13428
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 998244353
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 4010

ll n,s;
ll a[M];
ll dp[M][M];
ll f(ll pos, ll sum){
	if(sum > s) return 0;
	if(pos == n + 1){
		return sum == s;
	} 
	if(sum == s){
		return n + 2 - pos;
	}
	if(dp[pos][sum] != -1) return dp[pos][sum];
	ll ans = f(pos + 1, sum + a[pos]);
	if(!sum) (ans *= pos) %= md;
	(ans += f(pos + 1, sum)) %= md;
	return dp[pos][sum] = ans;
}
int main(){
	IOS;
	memset(dp,-1,sizeof(dp));
	cin>>n>>s;
	rep(i,1,n+1)cin>>a[i];
	
	cout<<f(1,0);
	
	
	
	return 0;
}



Measured memory_bytes: 126080
from string import ascii_lowercase, ascii_uppercase
s = open(0).read()
ans = [0]*26
for c in s:
    i = ascii_lowercase.find(c)
    if i > -1:
        ans[i] += 1
    i = ascii_uppercase.find(c)
    if i > -1:
        ans[i] += 1
for c, t in zip(ascii_lowercase, ans):
    print("%s : %d" % (c, t))


Measured memory_bytes: 6684
n = int(input())
d = {}
for i in range(n):
  s = input()
  d[s] = d.get(s, 0) + 1
m = max(d.values())
maxKeys = [x[0] for x in d.items() if x[1] == m]
so = sorted(maxKeys)
for e in so:
  print(e)


Measured memory_bytes: 99160
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define all(x) x.begin(), x.end()
bool isPowerOfTwo(int n)
{
    return (ceil(log2(n)) == floor(log2(n)));
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;



    return 0;

}


Measured memory_bytes: 3688
def min(x, y)
	x < y ? x : y
end

def shortest_distance(i, j, n, x, y)
	if i <= x && y <= j
		(x - i) + (j - y) + 1
	elsif i <= x && j < y
		dist = min(y - j + 1, j - x)
		(x - i) + dist
	elsif x < i && y <= j
		dist = min(i - x + 1, y - i)
		(j - y) + dist
	elsif x < i && j < y
		min(j - i, i - x + y - j + 1)
	end
end

def function(n, x, y)
	counts = Array.new(n, 0)
	(1...n).each do |i|
		((i + 1)..n).each do |j|
			distance = shortest_distance(i, j, n, x, y)
			counts[distance] += 1
		end
	end
	(1...n).each do |k|
		puts counts[k]
	end
end

n, x, y = gets.chomp.split.map(&:to_i)
function(n, x, y)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
main(){
  string S;
  cin>>S;
  S=regex_replace(S,regex("eraser"),"******");
  S=regex_replace(S,regex("erase"),"*****");
  S=regex_replace(S,regex("dreamer"),"*******");
  S=regex_replace(S,regex("dream"),"*****");
  cout<<(S==string(S.size(),'*')?"YES":"NO")<<endl;
}


Measured memory_bytes: 640
// Aizu 1196: Bridge Removal
// 2017.9.24 bal4u@uu

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

typedef struct { char f; int len, to[802], d[802]; } T;
T tbl[802];
int n;
int p[802], d[802];

int calc(int k)
{
	int i, j, max, s;

	if (tbl[k].f) return 0;
	tbl[k].f = 1;
	for (max = 0, i = 0; i < tbl[k].len; i++) {
		if ((j = tbl[k].to[i]) >= 0 && tbl[j].f == 0) {
			s = tbl[k].d[i] + calc(j);
			if (s > max) max = s;
		}
	}
	return max;
}

int main()
{
	int i, j, a, b, t, bridge, sum, max;
	T *q;

	while (scanf("%d", &n) && n) {
		memset(tbl, 0, sizeof(tbl));
		for (i = 1; i < n; i++) scanf("%d", &t), p[i] = t-1;
		for (sum = 0, i = 1; i < n; i++) scanf("%d", &t), d[i] = t, sum += t;
		for (i = 1; i < n; i++) {
			a = i, b = p[i];
			q = tbl + a, q->to[q->len] = b, q->d[q->len++] = d[i];
			q = tbl + b, q->to[q->len] = a, q->d[q->len++] = d[i];
		}
		bridge = sum;
		for (i = 0; i < n; i++) if (tbl[i].len == 1) {
			q = tbl + tbl[i].to[0];
			for (j = 0; j < q->len; j++) 
				if (q->to[j] == i) { sum -= q->d[j], q->to[j] = -1; break; }
		}

		for (max = 0, i = 0; i < n; i++) {
			if (tbl[i].len == 1) continue;
			for (j = 0; j < n; j++) tbl[j].f = 0;
			a = calc(i);
			if (a > max) max = a;
		}
		printf("%d\n", 2*sum + bridge - max);
	}
	return 0;
}

Measured memory_bytes: 6852