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

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

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, M, T, W;
map<string, int> mp;
ll V[8], P[8];
ll L[7], X[7], Y[7];
string R[8][8];
ll Q[8][8];

void input() {
    cin >> N >> M >> W >> T;
    for(int i = 0; i < M; i++) {
        string s;
        cin >> s;
        mp[s] = i;
        cin >> V[i] >> P[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> L[i] >> X[i] >> Y[i];
        for(int j = 0; j < L[i]; j++) {
            cin >> R[i][j] >> Q[i][j];
        }
    }
}

ll dp[10500];
vector<l_l> Query;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    for(int bits = 1; bits < (1 << N); bits++) {
        ll dist = 1e18;
        vector<ll> v;
        for(int j = 0; j < N; j++) {
            if(bits & (1 << j)) v.push_back(j);
        }
        do {
            ll now = 0;
            now += abs(X[v[0]]) + abs(Y[v[0]]);
            for(int i = 1; i < v.size(); i++) {
                now += abs(X[v[i]] - X[v[i-1]]);
                now += abs(Y[v[i]] - Y[v[i-1]]);
            }
            now += abs(X[v.back()]) + abs(Y[v.back()]);
            chmin(dist, now);
        } while(next_permutation(v.begin(), v.end()));
        //cerr << bits << " " << dist << endl;
        for(int i = 0; i <= W; i++) dp[i] = 0;
        for(int i = 0; i < N; i++) {
            if(!(bits & (1 << i))) continue;
            for(int j = 0; j < L[i]; j++) {
                ll val = P[mp[R[i][j]]] - Q[i][j];
                ll w = V[mp[R[i][j]]];
                for(int k = 0; k <= W; k++) {
                    if(k + w <= W) {
                        chmax(dp[k+w], dp[k] + val);
                    }
                }
            }
        }
        ll maxval = 0;
        for(int i = 0; i <= W; i++) {
            chmax(maxval, dp[i]);
        }
        Query.push_back({dist, maxval});
        //cerr << bits << " " << maxval << endl;
    }
    for(int i = 0; i <= T; i++) dp[i] = 0;
    for(auto tmp : Query) {
        for(int i = 0; i <= T; i++) {
            if(i + tmp.first <= T) {
                chmax(dp[i+tmp.first], dp[i] + tmp.second);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= T; i++) {
        chmax(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3324
h,w=gets.split.map(&:to_i)
a=(1..h).map{gets.chars}
h.times{|i|
  if a[i].any?{|x|x=='#'} then
    0.upto(w){|j|
      if a.transpose[j].count('.')<h then
        print a[i][j]
      end
    }
  end
}

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;


signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int n, c, k, ans = 0;
   cin >> n >> c >> k;
   vi t(n);
   for (int i = 0; i < n; i++) {
      cin >> t[i];
   }
   sort(t.begin(), t.end());
   int start  = -1, c1 = c;
   for (int i = 0; i < n; i++) {
      if (c1 == 0) {
         c1 = c, ans++, start = -1;
      }
      if (start == -1) {
         start = t[i];
         c1--;
      }
      else {
         if (start + k >= t[i]) c1--;
         else {
            start = t[i];
            c1 = c - 1;
            ans++;
         }
      }
   }
   cout << ans + 1;
}

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

struct edge{
    int to;
    int cost;
    edge(int a, int b){
        to=a;
        cost=b;
    }
};
typedef pair<long long, int> P;

struct D{
    vector<edge> G[200008]; //Graph
    long long d[200008],INF=1e18;
    
    void AddEdge(int from, int to, int cost){
        G[from].push_back(edge(to, cost));
    }
    
    void dijkstra(int n, int s){
        priority_queue<P, vector<P>, greater<P>> q;
        fill(d,d+n+1,INF);
        d[s]=0;
        q.push(P(0,s));
        while(!q.empty()){
            P p=q.top();
            q.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    q.push(P(d[e.to],e.to));
                }
            }
        }
    }
};


int main(void){
    int n,q,k;
    D d;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        d.AddEdge(a,b,c);
        d.AddEdge(b,a,c);
    }
    cin>>q>>k;
    d.dijkstra(n,k);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        cout<<d.d[x]+d.d[y]<<endl;
    }
}


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

/*条件によって味指標の最小値がなんであるのかが変わる*/

int main(){
  int N, L;
  int sum = 0;
  scanf("%d %d", &N, &L);

  for(int i = 1; i <= N; i++)
    sum += (L + i - 1);

  if(L <= 0 && L + N - 1 >= 0)           //味指標に0が含まれるとき
    cout << sum << endl;
  else if(L > 0)                                          //すべての味指標が自然数の時
    cout << sum - L << endl;
  else if(L + N - 1 < 0)                         //すべての味指標が負の整数の時
    cout << sum - L - N + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
#define mod 1000000007
using namespace std;
int main(){
	string s;cin>>s;
	string t,u;
	for(int i=0;i<s.size();i++){
		t+=(i%2)+'0';
		u+=(i+1)%2+'0';
	}

	int anst=0, ansu=0;
	for(int i=0;i<s.size();i++)if(s[i]!=t[i])anst++;
	for(int i=0;i<s.size();i++)if(s[i]!=u[i])ansu++;

	cout<<min(anst,ansu)<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
	vl x(n); rep(i,n) cin >> x[i];
	ll ans = linf;
	rep(i,101){
		ll cnt = 0;
		rep(j,n){
			cnt += (x[j]-i)*(x[j]-i);
		}
		chmin(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())

AS = [input().strip() for _ in range(N)]

nums = [int(a.replace('.', '')) for a in AS]
dens = [1 if '.' not in a else 10**(len(a) - a.index('.') - 1) for a in AS]

# print(nums, dens)

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a%b)

gs = [gcd(num, den) for num, den in zip(nums, dens)]
nums = [num // g for num, g in zip(nums, gs)]
dens = [den // g for den, g in zip(dens, gs)]

def signature(n):
    e2, e5 = 0, 0
    while n % 2 == 0:
        n //= 2
        e2 += 1
    while n % 5 == 0:
        n //= 5
        e5 += 1
    return (e2, e5)

lookup = defaultdict(int)
for num, den in zip(nums, dens):
    n2, n5 = signature(num)
    d2, d5 = signature(den)
    lookup[(n2-d2, n5-d5)]+=1

ans = 0
for k1 in lookup:
    for k2 in lookup:
        v1, v2 = lookup[k1], lookup[k2]
        x1, y1 = k1
        x2, y2 = k2
        if x1 + x2 >= 0 and y1 + y2 >=0:
            if k1 == k2:
                ans += v1*(v1-1)
            else:
                ans += v1*v2

ans //= 2
print(ans)





Measured memory_bytes: 50604
#include<iostream>

using namespace std;

int main() {
	int n; cin >> n;
	int a,sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += (a - 1);
	}
	cout << sum << endl;
	//system("pause");
	return 0;
}

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

using namespace std;
const int maxN=3e2+100;
int n,m,st,fn;
int cap[maxN][maxN],excess[maxN],height[maxN];
vector<int> g[maxN];
set<pair<int,int> > candidates;

void input()
{
  cin>>n>>m;
  //cin>>st>>fn;
  st=1; fn=n;
  for(int i=1;i<=m;i++)
    {
      int k1,k2,val;
      cin>>k1>>k2>>val;
      k1++;k2++;
      if(cap[k1][k2]==0 && cap[k1][k2]==0){
	g[k1].push_back(k2);
	g[k2].push_back(k1);
      }
      cap[k1][k2]+=val;
    }
}
int findExcessedVertex()
{
    while(candidates.size()>0)
      {
	auto item=*candidates.begin();
	if(item.second==st || item.second==fn)
	  candidates.erase(item);
	else
	  return item.second;
      }
    return 0;
}
bool push(int v)//change to multi push
{
  bool done=false;
  for(auto u :g[v])
    if(cap[v][u]>0 && height[v]==height[u]+1)
      if(cap[v][u]>0)
	{
	int delta=min(excess[v],cap[v][u]);
	cap[v][u]-=delta;
	cap[u][v]+=delta;
	excess[v]-=delta;
	if(excess[v]==0)
	  candidates.erase({height[v],v});
	if(excess[u]==0)
	  candidates.insert({height[u],u});
	excess[u]+=delta;
	done=true;
	return done;
      }
  return done;
}
void relabel(int v)
{
  height[v]++;
  if(candidates.find({height[v]-1,v})!=candidates.end()){
    candidates.erase({height[v]-1,v});
    candidates.insert({height[v],v});}
}
void GT_init()
{
  height[st]=n;
  height[fn]=0;//not done
  for(auto u:g[st])
    if(cap[st][u]>0)
      {
      int delta=cap[st][u];
      cap[st][u]-=delta;
      cap[u][st]+=delta;
      excess[st]-=delta;
      if(excess[st]==0)
	candidates.erase({height[st],st});
      if(excess[u]==0)
	candidates.insert({height[u],u});
      excess[u]+=delta;
    }
}
int Goldberg_Tarjan()
{
  GT_init();
  while(int v=findExcessedVertex())
    {
      
     // cout<<"gt "<<v<<" "<<excess[v]<<" "<<height[v]<<endl;
      if(!push(v))
	relabel(v);
    }
  return excess[fn];
}
int main()
{
  input();
  int Maxflow=Goldberg_Tarjan();
  cout<<Maxflow<<endl;
  
  return 0;
}

Measured memory_bytes: 3364
#include "bits/stdc++.h"
using namespace std;
int main(){
	int N, cnt = 1, sum=0;
	cin >> N;

	vector<int> d(N);

	for (int i = 0; i < N; i++){
		cin >> d.at(i);
	}
	for (int i = 0; i < N-1; i++){
		for (int j = cnt; j < N; j++){
			sum += d.at(i) * d.at(j);
			
		}
		cnt++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
typedef long long ll;
const int N = 11;
const int maxVal=15;
const int inf = (1<<20);
char m[N][N+1];
void repaint(vector<int> &in){
  int color[20];
  rep(i,20)color[i]=-1;
  color[0]=0;
  int cnt=1;
  rep(i,(int)in.size())if (color[in[i]] == -1)color[in[i]]=cnt++;
  rep(i,(int)in.size())in[i]=color[in[i]];
}

map<vector<int>,int> M[N*N];
int solve(const int r,const int c,const int now,vector<int> &st){
  //cout << now <<" : ";vp(st,st.size());
  if (now == r*c){
    repaint(st);
    rep(i,(int)st.size())if (st[i] >= 2)return -inf;
    return 0;
  }
  map<vector<int>,int>::iterator itr = M[now].find(st);
  if (itr != M[now].end())return (*itr).second;
  vector<int> next(st.size());
  int ret=-inf;
  int y=now/c,x=now%c;
  int up=st[0],left=st[st.size()-1];
  //put black
  if ((up == 0 || left == 0 || up != left || x == 0) && (m[y][x] == '?' || m[y][x] == '#')){
    rep(i,(int)st.size()-1)next[i]=st[i+1];
    if (y == 0){
      if (x == 0){
	next[next.size()-1]=1;
      }else {
	next[next.size()-1]=left!=0?left:maxVal;
	repaint(next);
      }
    }else if (x == 0){// y != 0
      if (up != 0){
	next[next.size()-1]=up;
      }else {
	next[next.size()-1]=maxVal;
	repaint(next);
      }
    }else {
      if (up == 0 && left == 0){
	next[next.size()-1]=maxVal;
	repaint(next);
      }else if (up == 0){//connected to left
	next[next.size()-1]=left;
      }else if (left == 0){//connected to upper
	next[next.size()-1]=up;
      }else {
	rep(i,(int)next.size()-1)if (next[i] == up || next[i] == left)next[i]=up;
	next[next.size()-1]=up;
	repaint(next);
      }
    }
    int tmp=solve(r,c,now+1,next);
    if (tmp != -inf)ret=max(ret,1+tmp);
  }

  //put white
  bool isok=true;
  if (y == 0 && x == 0){
    //always true
  }else if (y == 0){
    //always true
    if (left == 0)isok=false;
  }else if (x == 0){
    if (up == 0)isok=false;
    else if (c != 1 && count(st.begin(),st.end(),up) == 1)isok=false;
  }else {
    if (left == 0 || up == 0)isok=false;
    else if (c != 1 && count(st.begin(),st.end(),up) == 1)isok=false;
  }

  if (isok && (m[y][x] == '.' || m[y][x] == '?')){
    rep(i,(int)st.size()-1)next[i]=st[i+1];
    next[next.size()-1]=0;
    ret=max(ret,solve(r,c,now+1,next));
  }
  return M[now][st]=ret;
}

main(){
  int r,c;
  while(cin>>r>>c){
    rep(i,r)cin>>m[i];
    rep(i,r*c)M[i].clear();
    vector<int> in(c,0);
    int ans=solve(r,c,0,in);
    if (ans == -inf)cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 28000
N, M = map(int, input().split())
from collections import defaultdict, deque

graph = defaultdict(list)
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v + N)
    graph[u + N].append(v + 2 * N)
    graph[u + 2 * N].append(v)
S, T = map(int, input().split())
S -= 1
T -= 1

dist = [-1] * (3*N)
dist[S] = 0
que = deque([S])
while len(que) != 0:
    q = que.popleft()
    cost = dist[q]
    for v in graph[q]:
        if dist[v] == -1:
            dist[v] = cost + 1
            que.append(v)
if dist[T] % 3 == 0:
    print(dist[T] // 3)
else:
    print(-1)


Measured memory_bytes: 79644
#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 all(x) (x).begin(),(x).end()
#define dbg(x) cout<<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_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a+2,INF),t(b+2,INF),x(q,INF);
    s[0] = -INF;
    t[0] = -INF;
    // x[0] = INF;
    repl(i,1,a+1) cin>>s[i];
    repl(i,1,b+1) cin>>t[i];
    repl(i,0,q) cin>>x[i];
    rep(k,q){
        auto A = upper_bound(all(s), x[k]);
        auto B = upper_bound(all(t), x[k]);
        ll AA = A - s.begin();
        ll BB = B - t.begin();
        ll ans = INF;

        repl(i,AA-1,AA+1) repl(j,BB-1,BB+1) {
            ll d1 = abs(s[i] - x[k]) + abs(t[j] - s[i]);
            ll d2 = abs(t[j] - x[k]) + abs(s[i] - t[j]);
            ans = min(ans, min(d1, d2));
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
import java.util.*;

class Main{
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int num1 = sc.nextInt();
	int num2 = sc.nextInt();
	int num3 = sc.nextInt();

	if (num1 < num2 && num2 < num3){
		System.out.println("Yes");
	}else
		System.out.println("No");
	}
}


Measured memory_bytes: 26116
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

#define INF 1000000000000009LL
#define MOD 1000000007LL

ll dp[1<<25];
int a[21][21];

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }
  dp[0] = 1;
  for (int bit = 0; bit < (1<<N); bit++) {
    int pos = __builtin_popcount(bit) - 1;
    
    for (int i = 0; i < N; i++) {
      if ((bit & (1<<i)) && a[pos][i]) {
        dp[bit] += dp[bit ^ (1<<i)];
        dp[bit] %= MOD;
      }
    }
  }
  cout << dp[(1<<N) - 1] << endl;
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; //00右,01下,10左,11上

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int mask=(1<<12)-1;
int h,w,k,memo[50][50][4][1<<12];
char fld[50][50];

inline bool Check(int y,int x){
	return 0<=y&&y<h&&0<=x&&x<w&&fld[y][x]!='#';
}

inline int Max(int y,int x,int c,int bit){
	int &res=memo[y][x][c][bit];
	if(res!=-1) return res;
	if(y==h-1&&x==w-1&&c==0) return res=0;

	bool done=false;
	int py=y,px=x;
	rep(i,0,6){
		py-=dy[(bit>>(i*2))&3];
		px-=dx[(bit>>(i*2))&3];
		if(y==py&&x==px){
			done=true;
			break;
		}
	}
	int gift=0;
	if(!done&&fld[y][x]!='.') gift=fld[y][x]-'0';

	res=-INF;
	rep(i,0,4){
		int ny=y+dy[i],nx=x+dx[i];
		if(!Check(ny,nx)) continue;
		if(i<2){
			res=max(res,Max(ny,nx,c,((bit<<2)&mask)|i)+gift);
		}else if(c>=1){
			res=max(res,Max(ny,nx,c-1,((bit<<2)&mask)|i)+gift);
		}
	}

	return res;
}

void Solve(){
	fill_n((int*)memo,50*50*4*(1<<12),-1);
	cin >> h >> w >> k;
	rep(i,0,h) rep(j,0,w) cin >> fld[i][j];

	cout << Max(0,0,k,0) << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
string s[2];
void solve() {
    cin >> n;

    rep(i, 2 * n) {
        char c;
        cin >> c;
        s[i / n] += c;
    }

    all(reverse, s[1]);

    map<pair<string, string>, ll> mp;
    rep(i, 1 << n) {
        string s1, s2;
        rep(j, n) {
            if (((i >> j) & 1) == 1) s1 += s[0][j];
            else s2 += s[0][j];
        }

        ++mp[{s1, s2}];
    }

    ll ans = 0;
    rep(i, 1 << n) {
        string s1, s2;
        rep(j, n) {
            if (((i >> j) & 1) == 1) s1 += s[1][j];
            else s2 += s[1][j];
        }

        ans += mp[{s1, s2}];
    }

    cout << ans << endn;
}

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


Measured memory_bytes: 91904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 ll dp[2000][2000];



int main(){
   int n,a=0,b,h,m;
   string s;
   cin>>n>>s;
//    rep(i,n){
//        if(i>s.size())break;
//        cout<<s[i];
//        a++;
       
//    }
//    if(a<s.size())cout<<"...";
    if(s.size()>n)cout<<s.substr(0,n)<<"..."<<endl;
    else cout<<s<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>

const int inf = 1e9;

void print(std::vector<int> readvec){
    int sz = readvec.size();
    std::cout << "---" << std::endl;
    for(int i = 0; i < sz; ++i){
        std::cout << readvec.at(i) << std::endl;
    }
}
int main(){
    int n, w_limit;
    std::cin >> n >> w_limit;

    std::vector<int> w(n), v(n);
    for(int i = 0; i < n; ++i){
        std::cin >> w.at(i) >> v.at(i);
    }

    std::vector<std::vector<long>> dp(n + 1, std::vector<long> (w_limit + 1, 0));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= w_limit; ++j){
            long candidate;
            if(w.at(i) <= j){
                candidate = dp.at(i).at(j - w.at(i)) + v.at(i);
            }else{
                candidate = dp.at(i).at(j);
            }
            dp.at(i + 1).at(j) = std::max(dp.at(i).at(j), candidate);
        }
    }

    std::cout << *std::max_element(dp.at(n).begin(), dp.at(n).end()) << std::endl;

    return 0;
}

Measured memory_bytes: 80256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String inp[]= br.readLine().split(" ");
        int r= Integer.parseInt(inp[0]);
        int d= Integer.parseInt(inp[1]);
         long x= Long.parseLong(inp[2]);
        int i=10;
        while(i-->0)
        {
        	x=r*x-d;
        	System.out.println(x);
        }
	}
}

Measured memory_bytes: 21076
#!/usr/bin/env python
# coding: utf-8

# In[46]:


A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))


# In[47]:


cnddt = []
for i in range(len(A)):
    cnddt.append(A[i])
for i in range(len(A)):
    cnddt.append([x[i] for x in A])
cnddt.append([A[0][0],A[1][1],A[2][2]])
cnddt.append([A[0][2],A[1][1],A[2][0]])
# print(cnddt)
for i,cnddt_i in enumerate(cnddt):
    mylist = [x for x in cnddt_i if x not in b]
#     print(mylist)
    if len(mylist) == 0:
        print("Yes")
        break
else:
    print("No")


# In[ ]:






Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(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 fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

int ans = 0;
deque<int> marge(deque<int> l, deque<int> r) {
	deque<int> d;
	int siz = l.size() + r.size();
	rep(i,siz){
		ans++;
		if (r.empty() || (!l.empty() && l.front() < r.front())) {
			d.push_back(l.front());
			l.pop_front();
		}
		else {
			d.push_back(r.front());
			r.pop_front();
		}
	}
	return d;
}

deque<int> msort(deque<int> d) {
	if (d.size() == 1)return d;
	deque<int> l, r;
	int p = (d.size() + 1) / 2;
	rep(i, d.size()) {
		if (i < p)l.push_back(d[i]);
		else r.push_back(d[i]);
	}
	deque<int>ll = msort(l);
	deque<int>rr = msort(r);
	deque<int>dd =marge(ll, rr);
	return dd;
}


int main() {
	int n,in;
	cin >> n;
	deque<int> d,dans;
	rep(i, n) {
		cin >> in;
		d.push_back(in);
	}
	dans = msort(d);
	rep(i, dans.size()) {
		cout << dans[i] << (i != dans.size() - 1 ? " " : "");
	}
	cout << endl << ans << endl;
}



Measured memory_bytes: 15460
import java.util.*;
public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0;i<N;i++){
            arr[i] = sc.nextInt();
        }
        int[] dp = new int[N];
        for(int i= 1;i<N;i++) dp[i]= Integer.MAX_VALUE;
        dp[0] = 0;
        for(int i = 0;i<N-1;i++){
            if(i+1<N){
                dp[i+1] =Math.min(dp[i+1] ,dp[i] + Math.abs(arr[i+1] - arr[i]));
            }
            if(i+2<N){
                dp[i+2] =Math.min(dp[i+2] ,dp[i]+ Math.abs(arr[i+2] - arr[i]));
            }
        }
        System.out.println(dp[N-1]);
    }
}


Measured memory_bytes: 48112
#include <iostream>

using namespace std;

int main() {
     int d,n,k,v;
     cin>>n>>d;
     k=d*2+1;
     if(n%k==0){
         v=n/k;
     }
     else{
         v=n/k+1;
     }
    cout<<v;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    int N;
    cin >> N;
    vector<long> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    long maxtemp=0;
    for(int i=1;i<N;i++){
        if(H[i]+1<H[i-1]){
            cout << "No" << endl;
            exit(0);
        }
        if(maxtemp>H[i]+1){
            cout << "No" << endl;
            exit(0);
        }
        if(H[i]>maxtemp){
            maxtemp = H[i];
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<vector<int>> ar(n, vector<int>(32));
	rep(i, n){
		cin >> a[i];
		rep(j, 32){
			ar[i][j] = a[i]%2;
			a[i] /= 2;
//			cout << ar[i][j] << ' ';
		}
//		cout << endl;
	}
	rep(j, 32){
		int cou = 0;
		rep(i, n){
			cou += ar[i][j];
		}
		if(cou%2 == 1){
			rep(i, n){
				ar[i][j]--;
				ar[i][j] *= -1;
			}
		}
	}
	rep(i, n){
		int ans = 0;
		rep(j, 32){
			ans += ar[i][j] * pow(2,j);
		}
		cout << ans << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 36740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll n, m;
string str="";
cin >> n >> m;
multiset<string>map1;
for(ll i=0; i<n; i++){
	string s;
	cin >> s;
	map1.insert(s);
}
for(auto i : map1){
	str+=i;
}
cout << str;
return 0;
}



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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define ll long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	string s;
	cin >> s;
	int ans = 0;
	int n = s.size();
	rep(i, n) {
		//cout << "s[i]= " << s[i] << endl;
		ans += s[i]-'0';
		ans%=9;
		//println(ans);
	}
	if (ans % 9 == 0)print("Yes");
	else print("No");
}

Measured memory_bytes: 3704
#include <cstdint>
#include <iostream>

using namespace std;
using i64 = int64_t;

i64 f(i64 n,i64 m){
  if (n >= 2 && m >= 2) return (n - 2) * (m - 2);
  if (n == 1 && m == 1) return 1;
  return max(n, m) - 2;
  
}
int main()
{
  i64 n,m;
  cin >> n >> m;
  cout << f(n,m) << endl;
  
}


Measured memory_bytes: 256
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

typedef complex<double> P;
inline double inp(const P& a, const P& b) {
  return (conj(a)*b).real();
}

P vs[105];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int x, y;
    scanf("%d%d", &x, &y);
    vs[i] = P(x, y);
  }

  vector<P> cands;
  REP(i, n) {
    if(abs(vs[i]) > 0) {
      cands.push_back(vs[i]);
      cands.push_back(vs[i] * P(0, 1));
      cands.push_back(vs[i] * P(0, -1));
      cands.push_back(vs[i] * P(1, 1));
      cands.push_back(vs[i] * P(1, -1));
      REP(j, i) {
        cands.push_back(vs[i] + vs[j]);
      }
    }
  }
  double res = 0;
  for(P d : cands) {
    P cur(0, 0);
    REP(i, n) {
      if(inp(d, vs[i]) > 0) {
        cur += vs[i];
      }
    }
    res = max(res, abs(cur));
  }
  printf("%.15f\n", res);
  return 0;
}


Measured memory_bytes: 888
A,B,C,X,Y=map(int, input().split())
ans=A*X+B*Y
a=0
b=0

for i in range(1,1+2*max(X,Y)):
  if X-i/2<0:
    a=0
  else:
    a=X-i/2
  if Y-i/2<0:
    b=0
  else:
    b=Y-i/2
  ans = min(ans, A*a+B*b+C*i)
  
print(int(ans))

Measured memory_bytes: 9192
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n);
    REP(i,n) cin >> a[i];
    int now=0;
    int ans=0;
    sort(ALL(a));
    while(now<n){
        if(now+1<n&&a[now]==a[now+1]){
            now+=2;
        }else{
            now++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i=0; i<N; i++)

// dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    vector<int> h(N);
    Rep(i, N) {
        cin >> h[i];
    }

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int k=2; k<N; k++) {
        dp[k] = min(dp[k-2] + abs(h[k] - h[k-2]), dp[k-1] + abs(h[k] - h[k-1]));
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);
        int cnt = 0;
        for (int i = a; i <= b; i++){
            if (c%i == 0){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 17092
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
A = LIST()
s = 0
for a in A:
    s += (1/a)
print(1/s)

Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	ll t{},n{};
        string p;
        cin>>t>>n;
        std::vector<string> v(t) ;
        for(int i=0;i<t;i++){
            cin>>v[i];
        }
        sort(v.begin(),v.end());
        for(int i=0;i<t;i++){
            cout<<v[i];
        }
        cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define forn(i,x,y) for(int i=x;i<y;++i)
#define fornr(i,x,y) for(long long i=x;i>=y;--i)
#define testcase int _t; cin >> _t; while(_t--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 2e5;


int main()
{
	ios_base :: sync_with_stdio(false);
  	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n,weight;
	cin >> n >> weight;
	vector<int> w(n+1), cost(n+1);
	forn(i,1,n+1)
		cin >> w[i] >> cost[i];
	ll dp[n+1][weight+1]; 
	forn(i,0,n+1){
		forn(j,0,weight+1){
			if(!i && !j)
				dp[i][j] = 0;
			else
				dp[i][j] = -1;

		}
	}
	ll ans = 0;
	forn(i,1,n+1){
		forn(j,0,weight+1){
			if(dp[i-1][j] == -1 && j-w[i] < 0){
				dp[i][j] = -1; continue;
			}
			if(dp[i-1][j] == -1 && dp[i-1][j-w[i]] == -1){
				dp[i][j] = -1; continue;
			}
			if(j-w[i] < 0){
				dp[i][j] = dp[i-1][j]; continue;
			}
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + cost[i]);
			if(i == n)
				ans = max(ans,dp[i][j]);
		}
	}
	cout << ans;
	/*
		максимальная стоимость которую можно набрать из первых i подарков с весом равным j
		dp[i][j] = {
			dp[i-1][j],
			dp[i-1][j-w[i]] + cost[i]  	
		}
	
	*/
  	
  	
  	return 0;
}

 	/* 















 	*/


Measured memory_bytes: 82348
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    int N = s.length();
    int M = t.length();
    int m = min(N, M);
    for(int i = 0; i < m; ++i)
    {
        if(s[i] < t[i])
        {
            cout << "Yes" << endl;
            return 0;
        }
        else if(s[i] > t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    if(N < M) cout << "Yes" << endl;
    else  cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
  long long mod = 1000000007;
  int n, m;
  cin >> n >> m;
  long long a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    (a += x * ((i << 1) - n + 1)) %= mod;
  }
  for (int i = 0; i < m; i++) {
    long long y;
    cin >> y;
    (b += y * ((i << 1) - m + 1)) %= mod;
  }
  cout << (a * b) % mod << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <set>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <stack>
    #include <tuple>
    #include <map>
    #include <cassert>
     
    using namespace std;
    typedef long long ll;
     
    int main(){
        ll n, k;
        cin >> n >> k;
        ll max_k = (n - 2) * (n - 1) / 2;
        if(k > max_k){
            cout << -1 << endl;
            return 0;
        }
     
        set<pair<ll, ll>> edges;
        vector<pair<ll, ll>> pairs;
     
        for(ll i = 2; i <= n; ++i){
            edges.insert(make_pair(1, i));
        }
        for(ll i = 2; i <= n; ++i){
            for(ll j = i + 1; j <= n; ++j){
                pairs.push_back(make_pair(i, j));
            }
        }
     
        while(pairs.size() > k){
            auto p = pairs.back();
            pairs.pop_back();
            edges.insert(p);
        }
     
        cout << edges.size() << endl;
        for(auto p : edges){
            cout << p.first << ' ' << p.second << endl;
        }
        return 0;
    }

Measured memory_bytes: 640
n,X = map(int,input().split())
l =  list(map(int,input().split()))
l.sort(reverse = True)
ans = 10**10
yakusuu = []
count= 0
if n == 1:
  print(abs(l[0]-X))
  exit()
  
for i in l:
  ans = min(ans,abs(i-X))
  if i-X < 0:
    break

for i in range(1,ans+1):
  if ans%i == 0:
    yakusuu.append(i)

yakusuu.reverse()

for i in yakusuu:
  for j in range(n-1):
    if (l[j]-l[j+1])%i != 0:
      break
    elif (l[j]-l[j+1])%i == 0:
      count += 1
      if count == len(l) - 1:
        print(i)
        exit()
  

Measured memory_bytes: 14480
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
const int N = 2e5+5;
// vector<int> a;
int a[N];
int n,k;

int count(int x){
	int cnt = 0;
	rep(i,n){
		if(a[i] * a[i] <= x)	cnt--;

		if(a[i] == 0 && x >= 0)	cnt += n;
		else if(a[i] < 0){
			// cnt += n - (lower_bound(a.begin(), a.end(), (long double)x / a[i]) - a.begin());
			cnt += n - (lower_bound(a, a+n, (long double)x / a[i]) - a);
		}
		else if(a[i] > 0){
			// int pos = upper_bound(a.begin(), a.end(), (long double)x / a[i]) - a.begin();
			// cnt += pos;
			cnt += upper_bound(a, a+n, (long double)x / a[i]) - a;
		}

		// if(a[i] * a[i] < x)	cnt--;

		// if(a[i] <= 0){ // negative or zero
		// 	int l = -1,r = n;
		// 	while(r-l > 1){
		// 		int mid = (l+r) / 2;
		// 		if(a[i] * a[mid] < x)	r = mid;
		// 		else	l = mid;
		// 	}
		// 	cnt += n-r;
		// }
		// else{			// positive
		// 	int l = -1,r = n;
		// 	while(r-l > 1){
		// 		int mid = (l+r) / 2;
		// 		if(a[i] * a[mid] < x)	l = mid;
		// 		else	r = mid;
		// 	}
		// 	cnt += r;
		// }

		// cout << cnt << ' ';
	}
	// cout << endl << x << ' ' << cnt << endl;

	return cnt / 2;
}
// O(n * log(n) * log(C)), C = 1e18 

signed main(){
	IOS
	cin >> n >> k;
	// a.resize(n);
	rep(i,n)	cin >> a[i];
	// sort(a.begin(), a.end());
	sort(a,a+n);
	int l = -1e18+7, r = 1e18+7;
	while(r-l > 1){
		int mid = (l+r) / 2;
		if(count(mid) < k)	l = mid;
		else		r = mid;
	}
	cout << r << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll k;
    cin>>k;
    queue<ll>q;
    rep(1,i,10)q.push(i);
    ll ans;
    rep(0,i,k){
        ans=q.front();
        ll x=ans*10+ans%10;
        q.pop();
        if(ans%10!=0){
            q.push(x-1);
        }
        q.push(x);
        if(ans%10!=9){
            q.push(x+1);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using lint = long long;
int main() {
	lint n, m;
	scanf("%lld%lld", &n, &m);
	if (n == 1 && m == 1) {
		printf("1");
	}
	else if (n >= 2 && m >= 2) {
		printf("%lld", n*m - (n + m) * 2 + 4);
	}
	else {
		printf("%lld", std::max(n, m) - 2);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int k;
    int a[32] = {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};
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 3532
import java.util.Scanner;

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


Measured memory_bytes: 26216
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  while(true){
    str text;
    getline(cin, text);
    if(text[0] == '.') break;

    stack<char> c;
    bool flag = true;
    rep(i,0,text.size()){
      if(text[i] == '(') c.push('(');
      if(text[i] == '[') c.push('[');
      if(text[i] == ')'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '(') c.pop();
        else{
          flag = false;
          break;
        }       
      }

      if(text[i] == ']'){
        if(c.empty()){
          flag = false;
          break;
        }
        if(c.top() == '[') c.pop();
        else{
          flag = false;
          break;
        }
      }
    }
  
    if(flag && c.empty()) print("yes");
    else print("no");
  }
  
  return 0;
}



Measured memory_bytes: 3176
from itertools import accumulate as acc
class BIT:
  def __init__(self, n):
    self.N = n+1
    self.bit = [0]*self.N
  
  def bit_sum(self, i):
    s = 0
    i += 1
    while i>0:
      s += self.bit[i]
      i -= i & -i
    return s

  def bit_add(self, i, n):
    i += 1
    while i<self.N:
      self.bit[i] += n
      i += i & -i

N, K, *A = map(int, open(0).read().split())
A = [a-K for a in A]
B = [(b,i) for i, b in enumerate(acc(A))]
bit_B = BIT(N)
B.sort(reverse=True)
ans = sum(c[0]>=0 for c in B)
for b,i in B:
  bit_B.bit_add(i,1)
  ans += bit_B.bit_sum(N-1)-bit_B.bit_sum(i)
print(ans)

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

const int MOD = (int)1e9+7;

long long gcd(int a,int b){
  if(b==0)  return a;
  return gcd(b,a%b);
}

long long lcm(int N,int M){
  return (long long)N*M/gcd(N,M);
}

int main(){
  int N,M;
  string S,T;
  cin >> N >> M >> S >> T;

  long long L=lcm(N,M);
  long long a=gcd(N,M);
  long long n=N/a;
  long long m=M/a;
  bool flag=true;
  for(int i=0;i<a;i++){
    if(S.at(i*n)!=T.at(i*m))  flag=false;
  }
  if(flag)  cout << L << endl;
  else  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 512