akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<long long int>v[200005];
long long int vis[200005];
long long int cnt=0;
void dfs(long long int node){
    vis[node]=1;
    cnt+=1;
    for(long long int child:v[node]){
        if(!vis[child])
        dfs(child);
    }
}
int main(){
    set<long long int>s;
    long long int n,m,x,y;
    cin>>n>>m;
    for(long long int i=1;i<=m;i++){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    long long int inf=999999999;
    long long int maxi=-inf;
    for(long long int i=1;i<=n;i++){
        if(!vis[i]){
            cnt=0;
            dfs(i);
            maxi=max(maxi,cnt);
            
        }
    }
   cout<<maxi;
}

Measured memory_bytes: 22220
s = gets.chomp
k = gets.to_i

if s.split('').count(s[0]) == s.size
  puts s.size*k/2
  exit
end

ans = 0
cnt = 1
(s.size-1).times do |i|
  if s[i] == s[i+1]
    cnt += 1
  else
    ans += cnt / 2
    cnt = 1
  end
end
ans += cnt / 2

ans *= k



if s[0] == s[-1]
  i = 0
  while true
    if s[i] != s[i+1]
      break
    end
    i += 1
  end
  j = -1
  while true
    if s[j] != s[j-1]
      break
    end
    j -= 1
  end
  i += 1
  j *= -1
  ans -= ((i/2)+(j/2)-(i+j)/2)*(k-1)
end

puts ans

Measured memory_bytes: 1788
N = int(input())

L = list (map(int, input().split()))
count = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i] and L[i]!=L[j]and L[j]!=L[k] and L[k]!=L[i]:
                count +=1
print(count)

Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<map>
#define int long long
#define P pair<int,int>
using namespace std;
int n, W, w[100], v[100];
map<P,int> ma;
int rec(P p) {
	int res;
	if(ma.find(p)!=ma.end())return ma[p];
	if (p.first == n)res = 0;
	else if (p.second<w[p.first])res = rec(P(p.first + 1, p.second));
	else res = max(rec(P(p.first + 1, p.second)), rec(P(p.first + 1, p.second - w[p.first])) + v[p.first]);
	return ma[p]=res;
}
signed main() {
	cin>>n>>W;
	for (int i = 0; i<n; i++)cin>>w[i]>>v[i];
	cout<<rec(P(0,W))<<endl;
	return 0;
}

Measured memory_bytes: 6400
using System;
using System.Collections.Generic;

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

        for (int i = 3; i <= num; i++)
        {
            if (i % 3 == 0)
            {
                Console.Write(" " + i);
            }
            else
            {
                String strNum = i.ToString();
                char[] aryStrNum = strNum.ToCharArray();

                for (int j = 0; j < aryStrNum.GetLength(0); j++)
                {
                    if (aryStrNum[j] == '3')
                    {
                        Console.Write(" " + i);
                        break;
                    }
                }
            }
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 9392
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 1009
using namespace std;

int m,n,cnt; ll K; char s[N][N];
struct matrix{ int p[2][2]; }a,b;
matrix operator *(matrix x,matrix y){
	matrix z; memset(z.p,0,sizeof(z.p));
	int i,j,k;
	for (i=0; i<2; i++)
		for (j=0; j<2; j++)
			for (k=0; k<2; k++) z.p[i][k]=(z.p[i][k]+(ll)x.p[i][j]*y.p[j][k])%mod;
	return z;
}
int ksm(int x,ll y){
	int z=1; for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) z=(ll)z*x%mod;
	return z;
}
int main(){
	scanf("%d%d%lld",&m,&n,&K);
	if (K<=1){
		puts("1"); return 0;
	}
	int i,j;
	for (i=1; i<=m; i++) scanf("%s",s[i]+1);
	for (i=1; i<=n; i++)
		if (s[1][i]=='#' && s[m][i]=='#') break;
	bool flag1=(i<=n);
	for (i=1; i<=m; i++)
		if (s[i][1]=='#' && s[i][n]=='#') break;
	bool flag2=(i<=m);
	if (flag1 && flag2){
		puts("1"); return 0;
	}
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) cnt+=(s[i][j]=='#');
	if (!flag1 && !flag2){
		printf("%d\n",ksm(cnt,K-1)); return 0;
	}
	if (flag1){
		for (i=1; i<=max(m,n); i++)
			for (j=1; j<i; j++) swap(s[i][j],s[j][i]);
		swap(m,n);
	}
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++)
			if (s[i][j]=='#' && (j==1 || s[i][j-1]=='.')) a.p[0][0]++; 
	for (i=1; i<=m; i++)
		if (s[i][1]=='#' && s[i][n]=='#') a.p[0][1]++;
	b.p[0][0]=cnt; b.p[1][0]=mod;
	for (i=1; i<=m; i++)
		for (j=1; j<n; j++)
			if (s[i][j]=='#' && s[i][j+1]=='#') b.p[1][0]--;
	b.p[1][1]=a.p[0][1];
	for (K-=2; K; K>>=1,b=b*b) if (K&1) a=a*b;
	printf("%d\n",a.p[0][0]);
	return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A+B) > (C+D)) {
    cout << "Left" << endl;
  }
  if ((A+B) == (C+D)) {
    cout << "Balanced" << endl;
  }
  if ((A+B) < (C+D)) {  
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
    	
    Scanner sc =new Scanner(System.in);
    
    int l[]=new int[10];
        while(sc.hasNext()){
    	String []text = sc.nextLine().split(",");
        double dis=0.0; 
    	for(int i=0;i<10;i++){
        	l[i]=Integer.parseInt(text[i]); 
            dis+=l[i];
    	}

        double speed=Integer.parseInt(text[10])+Integer.parseInt(text[11]);  
        
        double time=dis/speed;
       
        double much=time*Integer.parseInt(text[10]);
        dis=0.0;
        for(int i=0;i<10;i++){
        	dis+=l[i];
        	if(dis>=much){
        		System.out.println(i+1);
        		break;
        	}
        }
    }
   }
}

Measured memory_bytes: 25668
import itertools

n = int(input())
v = [int(w) for w in input().split()]
assert len(v) == n

def elem_count(ls):
    '''Return the list of (num of elem, elem).'''
    ls.sort()
    ls = itertools.groupby(ls)
    cs = [(len(list(s)), e) for e, s in ls]
    cs.sort(reverse=True)
    return cs

e = [v[i] for i in range(0, n, 2)]
o = [v[i] for i in range(1, n, 2)]

e = elem_count(e)
o = elem_count(o)

candidate = []
if e[0][1] != o[0][1]:
    candidate.append(e[0][0] + o[0][0])
if len(e) > 1:
    candidate.append(e[1][0] + o[0][0])
if len(o) > 1:
    candidate.append(e[0][0] + o[1][0])
if len(e) == len(o) == 1:
    candidate.append(e[0][0])

print(n - max(candidate))


Measured memory_bytes: 15320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF 1e9

int main(){
    int n,m;
    cin>>n>>m;
    
    int a[1000],b[1000],c[1000],dist[100][100];
    
    
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dist[i][j]=INF;
        }
        dist[i][i]=0;
    }
    
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--,b[i]--;
        dist[a[i]][b[i]]=c[i];
        dist[b[i]][a[i]]=c[i];
    }
    
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    
    int res=0;
    for(int i=0;i<m;i++){
        if(c[i]>dist[a[i]][b[i]]) res++;
    }
    
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<pair<int, int>> range(q);
	rep(i, 0, q) cin >> range[i].first >> range[i].second;
	vector<LL> ans(n);
	rep (i, 1, n) {
		if (s.substr(i-1, 2) == "AC")
			ans[i] = 1;
	}
	vector<LL> accum(n + 1);
	rep(i, 0, n) {
		accum[i + 1] = accum[i] + ans[i];
	}
	rep(i, 0, q) {
		int l = range[i].first;
		int r = range[i].second;
		cout << accum[r] - accum[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 3456
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_pair(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

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

  vi x(n), y(n);
  rep(i, n){
    cin>>x[i]>>y[i];
  }
  dump(x);
  dump(y);

  vi p(n);
  iota(all(p), 0LL);
  // dump(p);

  double ans = 0;
  do{
    // dump(p);
    double d = 0;
    rep(i, 1, n){
      double dx = x[p[i]] - x[p[i-1]];
      double dy = y[p[i]] - y[p[i-1]];
      d += sqrt(dx*dx + dy*dy);
    }
    // dump(d);
    ans += d;
  } while (next_permutation(all(p)));

  int f = 1;
  rep(i, 1, n+1){
    f *= i;
  }
  // dump(f);

  printf("%.10f", ans/f);

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}

ll mex(vector<ll>&a, ll n)
{
  ll res=0;
  // set<ll>st;
  vector<ll>b(n+1,0);
  for(auto x:a) b[x]++;
    while(res<n && b[res]>0) res++;
  return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {
      string s,t;
      ll k,n;
      cin>>n>>k;
      cin>>s;
      t=s.substr(k-1,1);
      transform(t.begin(),t.end(),t.begin(),::tolower);
      s=s.substr(0,k-1) + t + s.substr(k,n-k);
      cout<<s;

    }

    return 0;
   }

Measured memory_bytes: 14100
import java.util.Scanner;
import java.math.BigDecimal;

public class Main{
	static double a,b,c,d,e,f,X,Y;
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			d = sc.nextInt();
			e = sc.nextInt();
			f = sc.nextInt();		//1??\?????????????????????????????????
			X = ((((c*e)/b)-f)/(((a*e)/b)-d));
			Y = ((f-((c*d)/a))/(e-((b*d)/a)));
			BigDecimal XX = new BigDecimal(X);
			BigDecimal YY = new BigDecimal(Y);
			BigDecimal XXX = XX.setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal YYY = YY.setScale(3, BigDecimal.ROUND_HALF_UP);
			System.out.println(XXX + " " + YYY);
		}
		sc.close();
	}
}

Measured memory_bytes: 26168
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int dis(string s, string t){
    int val=0;
    for(int i=0;i<t.length();i++){
        if(s[i]!=t[i])val++;
    }
    return val;
}
int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	
	string s,t;
	cin>>s>>t;
	int ans=INT_MAX;
	int m = t.length();
	int n = s.length();
	for(int i=0;i<=n-m;i++){
	    ans= min(ans,dis(s.substr(i,m),t));
	    
	}
	cout<<ans<<"\n";
	
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
const int a[] = {
  0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0
};
int p, q;
int main() {
  cin >> p >> q;
  --p; --q;
  cout << (a[p] == a[q] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


int n;
ll k;
const int dmax = 50;
//dp[上からi桁まで][smaller]
vector<vector<ll>> dp(100, vector<ll>(2, -1));

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

	cin >> n >> k;

	vector<ll> a(n);

	//cout << "a:" << endl;
	FOR(i, 0, n) {
		cin >> a[i];
		//cout << a[i] << endl;
	}

	dp[0][0] = 0;
	
	FOR(d, 0, dmax) {
		//cout << "---" << d << "---" << endl;
		//maskは2^(dmax - d - 1)が入る d:0~49に対してmask:0~のため1引く
		//mask: d桁目が1で残り0の数(10進数)
		ll mask = 1LL << (dmax - d - 1);
		//cout << "mask:" << mask << endl;

		//Aで元々d桁目にビットが立っている(d桁目が1)ものの個数
		//&: ビット演算(2進数に変換して計算)
		int num = 0;
		FOR(i, 0, n) if (a[i] & mask) num++;
		//cout << "num:" << num << endl;

		//xのd桁目を0,1にした時のコスト
		ll cost0 = mask * num;
		ll cost1 = mask * (n - num);
		//cout << "cost0:" << cost0 << endl;
		//cout << "cost1:" << cost1 << endl;

		//dp[ i ][ smaller ] -> dp [ i+1 ][ smaller ]への遷移
		
		//1. smaller -> smaller
		//0でも1でも自在に大きい方選ぶ
		if (dp[d][1] != -1) {
			chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1));
		}

		//2. exact -> smaller
		if (dp[d][0] != -1) {
			if (k & mask) { //kのd桁目が1なら、xのd桁目は0にする
				chmax(dp[d + 1][1], dp[d][0] + cost0);
			}
		}

		//3. exact -> exact
		//kにぴったり合わせる
		if (dp[d][0] != -1) {
			if (k & mask) chmax(dp[d + 1][0], dp[d][0] + cost1); //kのd桁目が1
			else chmax(dp[d + 1][0], dp[d][0] + cost0); //kのd桁目が0
		}
		
	}

	cout << max(dp[dmax][0], dp[dmax][1]) << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n);
  map<int, int> mp;
  rep(i, n) {
    cin >> A[i];
    mp[A[i]]++;
  }
  auto no = [&]() {
    cout << "Impossible" << "\n";
    exit(0);
  };
  int mx = mp.rbegin()->first;
  int mn = mp.begin()->first;
  if(mn != (mx+1)/2) no();
  if(mx%2==0 && mp[mx/2] != 1) no();
  if(mx%2==1 && mp[(mx+1)/2] != 2) no();
  int ib = (mx%2==0 ? mx/2+1 : (mx+1)/2+1);
  for(int i=ib; i<=mx; i++) {
    if(mp[i] < 2) no();
  }
  cout << "Possible" << "\n";
  return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
from collections import deque


H, W = [int(str) for str in input().strip().split()]
S = [list(input().strip()) for _ in range(H)]


def bfs():
    moves = ((1, 0), (0, 1), (-1, 0), (0, -1))
    dists = [[-1] * W for _ in range(H)]
    dists[0][0] = 0
    que = deque()
    que.append((0, 0))
    while len(que):
        ch, cw = que.popleft()
        for dh, dw in moves:
            nh, nw = ch + dh, cw + dw
            if (    0 <= nh < H 
                and 0 <= nw < W 
                and S[nh][nw] == '.' 
                and dists[nh][nw] == -1):
                dists[nh][nw] = dists[ch][cw] + 1
                que.append((nh, nw))

    return dists[-1][-1]


def solve():
    dist = bfs()
    if dist == -1:
        print(-1)
        exit()
    white = sum([1 for row in S for i in row if i == '.'])
    print(white - dist - 1)


solve()


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int maxi = *max_element(A.begin(), A.end());
    int best = 0;
    for (int i = 0; i < N; i++) {
        if (abs(maxi/2 - A[i]) < abs(maxi/2 - best)) {
            best = A[i];
        }
    }
    cout << maxi << " " << best << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using ll = long long;

#define DEBUG(a) cout<<#a<<" "<<a<<" #"<<__LINE__<<endl

auto R(int s, int n) {
    return boost::irange(s, n);
}
auto R(int n) {
    return boost::irange(0, n);
}
void show(const auto& v){
    for(auto i:v) cout << i << " ";
    cout << endl;
}

int main() {
    string a;
    cin>>a;
    vector<bool> x(26,false);
    int ans_size=1;
    vector<int> p{};
    for(int i=a.size()-1;i>=0;i--){
        x.at(a.at(i)-'a')=true;
        bool flag=true;
        for(auto b:x){
            if(!b){
                flag=false;
                break;
            }
        }
        if(flag){
            p.push_back(i);
            ans_size++;
            for(auto b:x){
                b=false;
            }
        }
    }
    reverse(p.begin(),p.end());
    function<int(int)> count_loop = [&](int start){
        for(int i:R(0,p.size())){
            if(start<=p[i]){
                return (int)(p.size()-i);
            }
        }
        return 0;
    };
    vector<vector<int>> y(26,vector<int>(0));
    for(int i:R(0,a.size())){
        y.at(a.at(i)-'a').push_back(i);
    }
    //'a'=0
    vector<int> ans(ans_size,0);
    vector<int> ans_id(ans_size,0);
    for(int i=0;i<ans_size-1;i++){
        while(true){
            int id=(i==0?0:ans_id.at(i-1)+1);
            for(int j=(i==0?0:ans_id.at(i-1)+1);j<a.size();j++){
                if(a.at(j)-'a'==ans.at(i)){
                    id=j;
                    break;
                }
            }
            for(int j:R(0,y.at(ans.at(i)).size())){
                if(id<=y.at(ans.at(i)).at(j)){
                    id=y.at(ans.at(i)).at(j);
                    break;
                }
            }
            //DEBUG(id);
            int c=count_loop(id+1);
            if(c<ans_size-1-i){
                ans_id.at(i)=id;
                break;
            }else{
                ans.at(i)++;
            }
        }
    }
    for(auto b:x){
        b=false;
    }
    for(int i=(ans_id.size()==1?0:ans_id.at(ans_id.size()-2)+1);i<a.size();i++){
        x.at(a.at(i)-'a')=true;
    }
    for(int i=0;i<26;i++){
        if(!x.at(i)){
            ans.at(ans.size()-1)=i;
            break;
        }
    }
    for(auto i:ans){
        cout<<(char)(i+'a');
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1412
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();

    int cou = 0;
    for(int i=0; i<=a; i++) {
    for(int j=0; j<=b; j++) {
    for(int k=0; k<=c; k++) {
    	if(i*500 + j*100 + k*50 == x){
    		cou++;
    	}
    }
    }
}
	System.out.println(cou);
      }
}

Measured memory_bytes: 35740
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
int main()
{
  using namespace std;//swap
  int n,value;
  cin>>n;
  vector<int> vec(n+1),ivec(n+1);
  for(int i=1;i<=n;i++)
  cin>>vec[i];
  for(int i=1;i<=n;i++)
  ivec[vec[i]]=i;
  for(int i=1;i<=n;i++)
  cout<<ivec[i]<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];
	int g = a[0];
	rep(i, n) g = gcd(g, a[i]);
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define MAX int(1e5)+5
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

int n, arr[MAX], dp[MAX];
const int INF = 1e9+5;

int main(int argc, char** argv) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		dp[i] = INF;
	}

	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j : {i+1, i+2})
			if (j < n)
				dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]));
	}

	cout << dp[n-1] << '\n';


	return 0;
}






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

#define MAX 30
#define BLANK 0
#define UP 1
#define RIGHT 2
#define DOWN 4
#define LEFT 8
#define VISITED 16

struct data{int y,x,distance;};

int main()
{
  int field[MAX][MAX];
  int direction[4]={UP,RIGHT,DOWN,LEFT};
  int dy[4]={-1,0,1,0};
  int dx[4]={0,1,0,-1};

  int w,h,a,ans;
  int i,j;

  while(cin>>w>>h,w|h){
    queue<data> q;
    for(i=0;i<MAX;i++)for(j=0;j<MAX;j++)field[i][j]=BLANK;
    for(i=0;i<h;i++){
      field[i][0]^=LEFT;
      field[i][w-1]^=RIGHT;
    }
    for(j=0;j<h;j++){
      field[0][j]^=UP;
      field[h-1][j]^=DOWN;
    }
    for(i=0;i<2*h-1;i++){
      for(j=0;~i&1 && j<w-1;j++){
	cin>>a;
	if(!a)continue;
	field[i/2][j]^=RIGHT;
	field[i/2][j+1]^=LEFT;
      }
      for(j=0;i&1 && (j<w);j++){
	cin>>a;
	if(!a)continue;
	field[i/2][j]^=DOWN;
	field[i/2+1][j]^=UP;
      }
    }
    ans=0;
    data d={0,0,1};
    field[0][0]^=VISITED;
    q.push(d);
    while(!q.empty()){
      data d=q.front(),dd;
      q.pop();
      if(d.y==h-1 && d.x==w-1){
	ans=d.distance;
	break;
      }
      for(i=0;i<4;i++){
	if(field[d.y][d.x]&direction[i])continue;
	dd.x = d.x+dx[i];
	dd.y = d.y+dy[i];
	dd.distance = d.distance+1;
	if(dd.x<0 || w<=dd.x || dd.y<0 || h<=dd.y)continue;
	if(field[dd.y][dd.x]&VISITED)continue;
	field[dd.y][dd.x]^=VISITED;
	q.push(dd);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 912
import sys
n=int(input())

if n == 1:
    print(0)
    sys.exit()

orgn=n
counter=0
for i in range(2,int((n**0.5) + 1) ):
    if n % i == 0:
        counter += 1
        n //= i
        wari=i**2
        while n % wari == 0:
            counter +=1
            n //= wari
            wari *= i
        
        while n % i ==0:
            n //= i

if n == orgn:
    print(1)
    sys.exit()

if n > int(n ** 0.5):
        counter+=1
print(counter)

Measured memory_bytes: 9464
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];
 
inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}
 
inline ll add(ll a, ll b){
    return take_mod(a+b);
}
 
inline ll sub(ll a, ll b){
    return take_mod(a-b);
}
 
 
inline ll mul(ll a, ll b){
    return take_mod(a * b);
}
 
inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}
 
ll mod_inv(ll x){
    return pow(x, mod-2);
}

void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}
 
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}
 
ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}
 
ll comb(ll n, ll k){
  return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

int done[200100];
     
int main(){
  ll N, K;

  cin >> N >> K;

#ifdef DEBUG
  cout << "N=" << N << "K=" << K << endl;
#endif

  make_fact(K);
  make_invfact(K);

  vector<ll> alist[N+1];
  ll u = 0;
  ll v = 0;
  for(int i = 1; i < N; ++i){
    done[i] = 0;
    cin >> u >> v;
    //cout << u << ".." << v << endl;
    alist[u].emplace_back(v);
    alist[v].emplace_back(u);
  }

  queue<ll> que;
  que.push(1);
  ll depth = 0;
  ll ans = K;
  while(!que.empty()){
    ll x = que.front();
    que.pop();
    done[x] = 1;
    ll cnt = 0;
    
    //cout << x << endl;
    
    for(size_t i = 0; i < alist[x].size(); ++i){
      
      if(!done[alist[x][i]]){
	//cout << "i=" << i << " x=" << x << " al[x][i]=" << alist[x][i] << endl;
	que.push(alist[x][i]);
	cnt++;
      }
    }
    if(depth == 0){
      ans = mul(ans, perm(K-1, cnt));
    } else {
      ans = mul(ans, perm(K-2, cnt));
    }
    //cout << "x: " << x << ".. a: " << ans << endl;
    
    depth++;
  }

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


Measured memory_bytes: 9332
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve(){
    string s; cin>>s;

    int a = 0,b = 0;
    if(s[0] == 'A') a++; else b++;
    if(s[1] == 'A') a++; else b++;
    if(s[2] == 'A') a++; else b++;
    
    if(a == 0 || b == 0) cout<<"No\n";
    else cout<<"Yes\n";
}

signed main(){

   FastRead;    

    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    X = []
    Y = []
    XY = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)
        XY.append((x, y))
    X.sort()
    Y.sort()

    ans = float('INF')
    for l in range(N):
        for r in range(l + 1, N):
            for d in range(N):
                for t in range(d + 1, N):
                    lx = X[l]
                    rx = X[r]
                    ty = Y[t]
                    dy = Y[d]
                    c = 0
                    for x, y in XY:
                        if lx <= x <= rx and dy <= y <= ty:
                            c += 1
                    if c >= K:
                        ans = min(ans, abs(rx - lx) * abs(ty - dy))
    print(ans)


main()


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

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

	int res = 1;
	int cnt = 0;
	for (int i = 2; i <= N; ++i) {
		int tmp = i / 2;
		int cnt_t = 1;
		while (tmp > 0) {
			++cnt_t;
			tmp /= 2;
		}
		if (cnt_t > cnt) {
			res = i;
			cnt = cnt_t;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    N, K = map(int, raw_input().split())
    A = list(map(int, raw_input().split()))
    
    # dp[i] := 残りの石の数がi個の時、勝ちか負けか(先手目線)
    dp = [0] * (K + 1)
    
    for i in range(K + 1):
        for a in A:
            if i - a < 0:
                continue
    
            if dp[i - a] == 0:
                dp[i] = 1
                break
    
    print('First' if dp[-1] else 'Second')
    
main()


Measured memory_bytes: 33052
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;


	int xdiff = x1 - x2;
	int ydiff = y1 - y2;

	cout << x2 + ydiff << " " << y2 - xdiff << " " << x1 + ydiff << " " << y1 - xdiff << endl;

	return 0;
}

Measured memory_bytes: 256
import math

n, d = [int(y) for y in input().split()]
x = []

for i in range(n):
  x.append([int(z) for z in input().split()])

distance = []

for i in range(n):
  for j in range(n):
    di = 0
    for k in range(d):
      di += (x[i][k]-x[j][k])**2
    di = math.sqrt(di)
    if (di == int(di)):
      distance.append(di)

print('{0}'.format(int((len(distance)-n)/2)))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int n,m;
void input()
{
    cin>>n>>m;
}

void solve()
{
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

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

Measured memory_bytes: 3652
n,m = [int(x) for x in input().split()]
d = 10**9 + 7

def kaijou(n):
	d = 10**9 + 7
	ans = 1
	for i in range(1,n+1):
		ans = ans * i
		ans = ans % d
	return ans

if n-m == 1:
	b = kaijou(m)
	ans = (b*b*n)%d
elif n-m == -1:
	b = kaijou(n)
	ans = (b*b*m)%d
elif n==m:
	b = kaijou(n)
	ans = (b*b*2)%d
else:
	ans = 0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
        int n;
        int array[100];
        cin >> n;
        for(int i=0 ; i<n ; i++ ){
                cin>> array[i];
                }
        for(int i=1 ; i<=n ; i++ ){
                int tmp=array[i];
                for(int l=0 ; l<n ; l++ ){
                        cout << array[l];
                        if(l<n-1)
                                cout<<" ";
                }
                cout << endl;
                int j=i-1;
                while(array[j]>tmp && j>=0){
                        array[j+1]=array[j];
                        j--;
                }
                array[j+1]=tmp;
        }
        return 0;
}




Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define PI 3.14159265358979

using namespace std;

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

  vector<int> l(n);

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

  sort(l.begin(), l.end());

  int num = 0;
  vector<int> sum(2001, 0);
  // 前準備
  sum[l[0] + l[1]]++;
  for (int i = l[0] + l[1]; i > 0; i--){
    sum[i - 1] = sum[i];
  }
  for (int i = 2; i < n; i++){
    num += sum[l[i] + 1];

    vector<int> tsum(2001, 0);
    for (int j = 0; j < i; j++){
      tsum[l[j] + l[i]]++;
    }
    for (int j = 2000; j > 0; j--){
      tsum[j - 1] += tsum[j];
    }
    for (int j = 1; j < 2001; j++){
      sum[j] += tsum[j];
    }
  }


  cout << num << endl;

  return 0;
}


Measured memory_bytes: 256
<?php

/**
 * 入力
 */
function getData()
{
    $str = fgets(STDIN);
    $list = explode(' ', $str);
    return array_slice($list, 1);
}

/**
 * 全員が好きな食べ物のチェック
 */
function check($data, $n)
{
    $result = 0;
    foreach ($data as $d) {
        if ($d == $n) {
            $result++;
        }
    }
    return $result;
}

function main()
{
    // 入力
    fscanf(STDIN, "%d %d", $n, $m);

    $data = [];
    for ($i = 0; $i < $n; $i++) {
        $list = getData();
        foreach ($list as $l) {
            $idx = (int) $l;
            if (empty($data[$idx])) {
                $data[$idx] = 1;
            } else {
                $data[$idx]++;
            }
        }
    }

    $result = check($data, $n);

    // 出力
    echo $result . "\n";
}

main();


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef unsigned long long ll;
typedef pair<int,int> pint;

const ll x=1000000007;
string t,p;
int main(){
    cin>>t>>p;
    ll st=t.size(),sp=p.size();
    if(st<sp) return 0;
    ll q=1;
    rep(i,sp) q=q*x;
    ll ht=0,hp=0;
    rep(i,sp){
        ht=(ht*x+t[i]);
        hp=(hp*x+p[i]);
    }
    rep(i,st-sp+1){
        if(ht==hp) cout<<i<<endl;
        if(i<st-sp)ht=ht*x+t[i+sp]-q*t[i];
    }
    return 0;
}


Measured memory_bytes: 4012
N, M = map(int, input().split())
foodlist = [0 for i in range(M)]
for i in range(N):
    food = list(map(int, input().split()))
    food.pop(0)
    for items in food:
        foodlist[items-1]+=1
cnt = 0
#print(foodlist)
for i in range(M):
    if(foodlist[i] == N): cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    long long n;
    std::cin >> n;

    std::list<long long> a;
    for (int i = 0; i < n; i++) {
        long long temp;
        std::cin >> temp;

        if (i % 2) {
            a.push_back(temp);
        } else {
            a.push_front(temp);
        }
    }

    if (n % 2 == 0) {
        std::reverse(a.begin(), a.end());
    }

    long long i = 0;
    for (auto t = a.begin(); t != a.end(); t++) {
        printf("%lld%c", *t, i == n - 1 ? '\n' : ' ');
        i++;
    }
}


Measured memory_bytes: 8448
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
using ll = long long;

bool a[100010]; // false: prime_number
int c[100010];

int main() {
	int Q;
	cin >> Q;
	for (int i = 2; i <= 100000; i++) {
		if (!a[i]) {
			for (int j = i + i; j <= 100000; j += i) a[j] = true;
		}
	}
	for (int i = 3; i <= 100000; i += 2) {
		if (!a[i] && !a[(i + 1) / 2]) c[i]++;
	}
	for (int i = 3; i <= 100000; i++) c[i] += c[i - 1];
	for (int q = 0; q < Q; q++) {
		int l, r;
		cin >> l >> r;
		cout << c[r] - c[l - 1] << endl;
	}
	return 0;
}

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

const int N = 64;
const int INF = 19191919;

int n;
string a[128];

int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
int dp[N][N][N][N];

bool is_candidate(int lx, int ly, int rx, int ry, int X, int Y)
{
    if(a[Y][X]!='x') return false;
    bool ret = true;
    for(int i=lx; i<=rx; ++i) ret &= (a[Y][i]=='x');
    for(int i=ly; i<=ry; ++i) ret &= (a[i][X]=='x');
    return ret;
}

int f(int lx, int ly, int rx, int ry)
{
    if(dp[lx/2][ly/2][rx/2][ry/2]<INF) return dp[lx/2][ly/2][rx/2][ry/2];

    // printf("CALL %d %d %d %d\n", lx,ly,rx,ry);

    bool is_empty=true;
    for(int i=ly; i<=ry; ++i)for(int j=lx; j<=rx; ++j)if(a[i][j]=='x') is_empty = false;
    if(is_empty) return 0;

    int ret = INF;
    for(int i=ly+1; i<ry; i+=2)for(int j=lx+1; j<rx; j+=2)
    {
        // ???????????????????£?
        if(is_candidate(lx,ly,rx,ry,j,i))
        {
            // printf("  !CANDIDATE %d %d\n", i,j);
            ret = min(ret, 1+f(lx,ly,j-1,i-1)+f(j+1,ly,rx,i-1)+f(lx,i+1,j-1,ry)+f(j+1,i+1,rx,ry));
        }
    }

    return dp[lx/2][ly/2][rx/2][ry/2] = ret;
}

int main()
{
    rep(i,N)rep(j,N)rep(k,N)rep(l,N) dp[i][j][k][l]=INF;

    cin >>n;
    rep(i,n) cin >>a[i];
    cout << f(0,0,n-1,n-1) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    vector<pll> P(N);
    REP(i,0,N) cin >> P[i].first >> P[i].second;
    
    ASC(P);
    REP(i,0,N) {
        if(K > P[i].second) K -= P[i].second;
        else {
            PR(P[i].first);
            break;
        }
    }

    return 0;
}

/*



*/

Measured memory_bytes: 4772
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<class T>//ex) auto dp = make_vec(4,4,4,INF);
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}


int main() {

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

	Int N;
	cin >> N;

	string S;
	cin >> S;

	auto dp = make_vec(N + 1, 4, 1000, false);//dp[i+1][j][k]:i文字目まで見てj文字確定したときの文字列kが実現できるなら1
	dp[0][0][0] = 1;

	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < 3; j++) {
			for (Int k = 0; k < 100; k++) {
				if (!dp[i][j][k]) {
					continue;
				}
				//i文字目を選択する場合
				dp[i + 1][j + 1][10 * k + (S[i] - '0')] = true;
			
				//i文字目を選択しない場合
				dp[i + 1][j][k] = true;
			}
		}
	}

	Int ans = 0;
	vector<bool> seen(1000,false);
	for (Int i = 1; i <= N; i++) {
		for (Int k = 0; k < 1000; k++) {
			if (dp[i][3][k]) {
				if (seen[k]) {
					continue;
				}
				ans++;
				seen[k] = true;
			}
		}
	}
	cout << ans << "\n";

}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int graph[15][15];

int main() {
  int N;
  cin >> N;
  rep(i, N) rep(j, N) graph[i][j] = -1;
  rep(i, N) {
    int A;
    cin >> A;
    rep(j, A) {
      int x, y;
      cin >> x >> y;
      --x;
      graph[i][x] = y;
    } 
  }
  int ans = 0;  
  for (int bit = 0; bit < (1<<N); bit++) {
    if (__builtin_popcount(bit) <= ans) continue;
    vector<int> temp(N);
    for (int i = 0; i < N; i++) {
      if ((bit>>i)&1) temp[i] = 1;
    }
    bool flag = true;
    rep(i, N) {
      if (temp[i] == 0) continue;
      rep(j, N) {
        if (graph[i][j] == -1) continue;
        if (graph[i][j] != temp[j]) {
          flag = false;
        }
      }
    }
    if (flag) ans = __builtin_popcount(bit);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define MAX 50
#define NIL -1
using namespace std;
struct Node{
  int parent;
  int left;
  int right;
};
Node T[MAX];
int n;
void preParse(int node){
    if(node==NIL)   return;
    cout<<" "<<node;
    preParse(T[node].left);
    preParse(T[node].right);
}
void inParse(int node){
    if(node==NIL)   return;
    inParse(T[node].left);
    cout<<" "<<node;
    inParse(T[node].right);
}
void postParse(int node){
    if(node==NIL)   return;
    postParse(T[node].left);
    postParse(T[node].right);
    cout<<" "<<node;
}
void init(){
	int node,l,r;
	for(int i=0;i<n;i++){
		cin>>node>>l>>r;
		T[node].left=l;
		T[node].right=r;
		if(T[node].left!=NIL)
			T[l].parent=node;
		if(T[node].right!=NIL)
			T[r].parent=node; 
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		T[i].parent=NIL;
	}	
	init();
	int root;
	for(int i=0;i<n;i++)
		if(T[i].parent==NIL)
			root = i;
	cout<<"Preorder"<<endl;
	preParse(root);
	cout<<endl<<"Inorder"<<endl;
	inParse(root);
	cout<<endl<<"Postorder"<<endl;
	postParse(root);
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3084
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= len(x):
    print(0)
    exit()

ls = []
x.sort()

for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)

ls.sort(reverse=True)
ans = sum(ls)

for i in range(n-1):
    ans -= ls[i]

print(ans)


Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using ii = pair<ll, ll>;
#define ff first 
#define ss second
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define MAXN 100010

const ll INF = 1e18+100;

int main(){
	ios::sync_with_stdio(0);
	int t;
	cin >> t;
	while(t--){
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;
		priority_queue<ii> pq;
		map<ll, ll> mp;
		pq.push({0, n});
		while(not pq.empty()){
			ll k = pq.top().ss;
			ll v = -pq.top().ff; pq.pop();
			if(mp.find(k)==mp.end()) mp[k] = INF;
			if(mp[k]>v) mp[k] = v;
			else continue;

			if(k==0) continue;
			
			ll c2 = min((k/2)*d, a);
			ll c3 = min((k/3)*d*2, b);
			ll c5 = min((k/5)*d*4, c);
			if(k%2==0){ 
				pq.push({-(v+c2), k/2});
			}
			else{
				ll ca = v+(k%2)*d + c2;
				ll cb = v+(2-k%2)*d + min(((k+1)/2)*d, a);
				pq.push({-ca, k/2});
				pq.push({-cb, (k+1)/2});
			}
			if(k%3==0){
				pq.push({-(v+c3), k/3});
			}
			else{
				ll ca = v+(k%3)*d + c3;
				ll cb = v+(3-k%3)*d + min(((k+2)/3)*d*2, b);
				pq.push({-(ca), k/3});
				pq.push({-(cb), (k+2)/3});
			}
			if(k%5==0){
				pq.push({-(v+c5), k/5});
			}
			else{
				ll ca = v+(k%5)*d + c5;
				ll cb = v+(5-k%5)*d + min(((k+4)/5)*d*4, c);
				pq.push({-ca, k/5});
				pq.push({-cb, (k+4)/5});
			}
		}
		cout << mp[0] << endl;
	}
}


Measured memory_bytes: 4364
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>

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

    int n;
    cin>>n;
    ll ar[n];
    for(ll i=0;i<n;++i)
    {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    cout<<ar[n-1]-ar[0];

return(0);
}


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

struct BipartiteMatching {
    vector<vector<int>> graph;
    vector<int> match, used;
    int V;

    BipartiteMatching(int V) : V(V), graph(V), match(V, -1), used(V) {}

    void add_edge(int u, int v) {
        graph[u].emplace_back(v);
        graph[v].emplace_back(u);
    }

    bool dfs(int v) {
        used[v] = true;
        for (int i = 0; i < graph[v].size(); i++) {
            int u = graph[v][i], w = match[u];
            if (w < 0 || !used[w] && dfs(w)) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching() {
        int res = 0;
        for (int v = 0; v < V; v++) {
            if (match[v] < 0) {
                fill(begin(used), end(used), 0);
                if (dfs(v)) res++;
            }
        }
        return res;
    }
};

int main() {
    int X, Y, E;
    cin >> X >> Y >> E;
    BipartiteMatching g(X + Y);
    for (int i = 0; i < E; i++) {
        int x, y;
        cin >> x >> y;
        g.add_edge(x, X + y);
    }
    cout << g.bipartite_matching() << endl;
}


Measured memory_bytes: 3284