akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;

int a[200010];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=k;i<n;i++){
        if(a[i]>a[i-k]) puts("Yes");
        else puts("No");
    }
}


Measured memory_bytes: 4436
n = int(input())
a = list(map(int, input().split()))

ans = 0
nonleaf_nodes = []
current = 1

# とりあえず増やせるだけ頂点を増やしていく
for depth in range(0, n+1):
    c = current-a[depth]
    # 目いっぱい頂点を増やしても葉を賄えない場合、木を作れない
    if c < 0:
        print(-1)
        exit()
    nonleaf_nodes.append(c)
    current = c*2
nonleaf_nodes[-1]=0

# 余計な頂点を最深層から削除していく
# 下位層の葉を含む頂点数を超えると上位層で葉が増えるのでNG
ans = a[-1]
for depth in range(n-1, -1, -1):
    nonleaf_nodes[depth] = min(nonleaf_nodes[depth], nonleaf_nodes[depth+1]+a[depth+1])
    ans += nonleaf_nodes[depth] + a[depth]
print(ans)
    

Measured memory_bytes: 673492
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int ans = s.size();

	for(int i = 0; i < 2; i++)
	{
		int cnt = 0;
		for(int j = 0; j < s.size(); j += 1)
		{
			if((j % 2 == 0) ^ (s[j] == char(i + '0'))) cnt++;
		}
		ans = min(ans, cnt);
	}

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

Measured memory_bytes: 512
//??????????§????(??????or???????????????????????£?????????)???????????¨, ????¨??????????t??§??¨?????°???????????¨???, t<X??????X-t[m], t>=X??????0[m]?????????????????????
//??????????????????????????????????????£???, (??????, ????????§?????????)????????§??????????§????????±??????????
//????????????????????????????????????????????§????????????????°?????????????(2?§???????2m????????????????????£?????¨?????????, 2?§????????????¨??????????????°??????)?????§????????????????????????????????§?§£?????????
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define int long long
using namespace std;

int n, m, x;
int h[100000];
vector<int> et[100000];
vector<int> ec[100000];

signed main() {
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) cin >> h[i];

	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c; a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
		ec[a].push_back(c);
		ec[b].push_back(c);
	}
	
	static int minCost[100000];
	for (int i = 0; i < n; i++) minCost[i] = 1145141919893810;
	
	typedef pair<int, int> P;	//cost, pos
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P now = que.top(); que.pop();
		int cst = now.first;
		int pos = now.second;
		if (minCost[pos] <= cst) continue;
		minCost[pos] = cst;
		
		for (int i = 0; i < et[pos].size(); i++) {
			int height = max(0LL, x - cst);
			int npos = et[pos][i];
			
			if (height - ec[pos][i] > h[npos]) {
				que.push(P(x - h[npos], npos));			//Down
			}
			else if (height - ec[pos][i] > 0) {
				que.push(P(cst + ec[pos][i], npos));	//Sonomama
			}
			else {
				if (h[pos] < ec[pos][i]) continue;		//Cannot move
				que.push(P(cst + 2 * ec[pos][i] - height, npos));	//Up -> move
			}
		}
	}
	if (minCost[n - 1] >= 1145141919893810) { cout << -1 << endl; }
	else { cout << minCost[n - 1] + h[n - 1] - max(0LL, x - minCost[n - 1]) << endl; }
	return 0;
}

Measured memory_bytes: 39912
// Garg's Code
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
 
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++)
#define rf(i,x,n) for(ll i = x; i >= x; i--) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const ll MAX = LLONG_MAX, mod = 1000000007, MODA = 1e9 - 1;
const ll MIN = LLONG_MIN;
const long double PI = 3.1415926535;
const ll N = 400009;

int main()
{
  fast();

  
  ll n, m;
  cin >> n >> m;
  cout << int(ceil((n*1.0)/m));
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("trapv")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int maxn = 5005, mod = 998244353;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, t;
	set<int> a;
	cin >> n;
	while(n--) {
		cin >> t;
		if(!a.insert(t).second) return cout << "NO", 0;
	}
	cout <<"YES";
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
 
typedef long long int64;
const int INF = 1 << 30;

int N, a[20];
double dp[20][200001];

int main(){

  fill_n( *dp, 20 * 200001, (double)INF);

  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> a[i];
  }
  for(int i = 1; i < 200001; ++i){
    dp[0][i] = fabs(a[0] - i) / a[0];
  }
  for(int i = 0; i < N - 1; ++i){
    for(int j = 1; j < 200001; ++j){
      if(dp[i][j] != (double)INF){
        for(int k = j; k < 200001; k += j){
          dp[i + 1][k] = min( dp[i + 1][k], max( dp[i][j], fabs( a[i + 1] - k) / a[i + 1]));
        }                
      }
    }
  }
  cout << fixed << setprecision(10) << *min_element( dp[N - 1], dp[N]) << endl;
}

Measured memory_bytes: 32488
s=list(input())
ss=len(set(s))
if ss==1 or ss==3:
  print('No')
elif ss==4:
  print('Yes')
else:
  if 'N' in s and 'S' in s:
    print('Yes')
  elif 'W' in s and 'E' in s:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  string s;
  int Q;
  cin>>s>>Q;
  int y,F;
  char c;
  string t;
  int cnty=0;
  for(int i=0;i<Q;i++){
    cin>>y;
    if(y==1){
      swap(s,t);
    }
    if(y==2){
      cin>>F>>c;
      if(F==1){t+=c;}
      if(F==2){s+=c;}         
    }
  }
  reverse(t.begin(),t.end());
  t+=s;
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 4004
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32, k: i32,
    }

    let ans: i32;

    if n % k == 0 {
        ans = 0;
    } else {
        ans = 1;
    }

    println!("{}", ans);
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int N, ans=0, K;
  string S;
  cin >> N >> K;
  cin >> S;
  for(int i=0;i<N-1;i++){
    if(S[i] ==S[i+1]){
      ans++;
    }  
  }  
  ans = min(N-1,ans+K*2);
  cout << ans << endl;

  return 0;
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void func_to_create(){
    uint64_t N, K;
    cin >> N >> K;
    std::vector<uint64_t> A;
    A.reserve(N);
    for (uint64_t i = 0 ; i < N; i++){
        uint64_t a; 
        cin >> a;
        A.push_back(a);
    }
    std::map<uint64_t, uint64_t> step_map;
    std::vector<uint64_t> step_history;
    uint64_t current_step = 0;
    uint64_t current_city = 1;
    uint64_t cycle = 0;
    step_map[current_city] = current_step;
    step_history.push_back(1);

    while(true){
        uint64_t next_city = A[current_city - 1];
        step_history.push_back(next_city);
        current_step++;
        if( K == current_step){
            cout << next_city << endl;
            return;
        }
        if( step_map.find(next_city) != step_map.end()){
            // cout << "loop hole " << next_city << " in  " << step_map[next_city]
            // << " - " << current_step << endl;
            current_city = next_city;
            cycle = current_step - step_map[next_city];
            break;
        }else{
            current_city = next_city;
            step_map[next_city] = current_step;
        }
    }
    K -= step_map[current_city];
    K = K % cycle;
    K += step_map[current_city];
    cout << step_history[K] << endl;
}
int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    func_to_create();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

typedef vector<vector<int>> Graph;
vector<ll> hashv(111111,0);

ll dfs(const Graph &tree, int node){
    int sz=tree[node].size();
    if(sz==0){
        return hashv[node] = 1;
        
    }

    ll tmp=0;
    for(int i=0;i<sz;i++){
        int next=tree[node][i];
        tmp += dfs(tree,next);
    }
    tmp *= MOD;
    tmp += 1;
    return hashv[node] = tmp;
}

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

    int n;cin>>n;
    Graph tree(n);
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        tree[a].push_back(b);
    }
    dfs(tree,0);
    map<ll,ll> mp;
    ll res=0;
    for(int i=0;i<n;i++){
        res += mp[hashv[i]];
        mp[hashv[i]]++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 21544
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v : Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let n = v[0];
    let a = v[1];
    let b = v[2];
    //println!("{} {} {}", n, a, b);
    let mut ans = 0;
    for x in 0..(n+1) {
        let mut y = x;
        let mut k = 0;
        while y > 0 {
            k += y % 10;
            y /= 10;
        }
        if a <= k && k <= b {
            ans += x;
        }
    }
    println!("{}", ans);
}


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

typedef vector <ll> vl;
typedef pair< ll, ll > pll;


int main()
{
    ll t,i,j,k,ans,n,sum;

    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n;
        vl v(n+1);

        rep(p, 1, n+1) {
            cin>>v[p];
            v[p]-=p;
            //cout<<v[p]<<"\n";
        }
        sort(v.begin()+1,v.end());
        k = v[n/2 + 1],ans=0;
        //cout<<k<<"\n";
        rep(p, 1, n+1) {
            ans+=abs(v[p]-k);
            //cout<<abs(v[p]-k)<<"\n";
        }
        cout<<ans;
    }
    
    return 0;
}


Measured memory_bytes: 4808
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static long[] A;
	static ArrayList<Integer>[] adj;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		A = new long[N];
		int[] a = new int[N - 1];
		int[] b = new int[N - 1];
		adj = new ArrayList[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < N - 1; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			adj[a[i] - 1].add(b[i] - 1);
			adj[b[i] - 1].add(a[i] - 1);
		}
		sc.close();

		String ans = getCnt(0, -1) == 0 ? "YES" : "NO";
		System.out.println(ans);
	}

	private static long getCnt(int cur, int parent) {
		if (parent != -1 && adj[cur].size() == 1) {
			return A[cur];
		}
		long max = 0;
		long sum = 0;
		for (int child : adj[cur]) {
			if (child == parent) {
				continue;
			}
			long cnt = getCnt(child, cur);
			if (cnt == -1) {
				return -1;
			}
			sum += cnt;
			max = Math.max(cnt, max);
		}
		if (parent == -1 && adj[cur].size() == 1) {
			return A[cur] == sum ? 0 : -1;
		}
		if (A[cur] > sum) {
			return -1;
		}
		if (sum - A[cur] > sum - max || sum - A[cur] > sum / 2) {
			return -1;
		}
		return 2 * A[cur] - sum;
	}
}


Measured memory_bytes: 108808
n = gets.to_i
i = 2
ans = 0

while 1 < n
   if Math.sqrt(n) < i
    ans += 1
    break
  end
 
  if n % i == 0
    c = 0
    while n % i == 0
	  n /= i
      c += 1
    end

    d = 1
    while d <= c
      c -= d
      d += 1
      ans += 1
    end
  end
  i += 1
end


puts ans


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

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

  vec<int> X(n), Y(m);
  rep (i, n) {
    cin >> X[i];
  }
  rep (i, m) {
    cin >> Y[i];
  }
  sort(all(X));
  sort(all(Y));

  int xMax = X.back();
  int yMin = Y.front();

  for (int z = xMax + 1; z <= yMin; z++) {
    if (z > x and z <= y) {
      puts("No War");
      return 0;
    }
  }

    puts("War");


}


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

#define ss second
#define ff first
#define N 200005
#define ll long long
#define mod 1000000007
#define pb push_back
#define inf 1000000009
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

ll n,k;
ll ans,fact[2 * N];

ll der(ll a,ll b){
	if(b == 0) return 1;
	ll x = der(a,b / 2);
	if(b % 2) return (((x * x) % mod) * a) % mod;
	return (x * x) % mod;
}

ll C(ll n,ll k){
	return (fact[n] * der((fact[n - k] * fact[k]) % mod,mod - 2)) % mod;
}

ll num(ll n,ll k){
	k -= n;
	return C(n + k - 1,k);
}

int main()
{
	scanf("%lld%lld",&n,&k);
	fact[0] = 1;
	for(int i = 1;i <= n + min(n,k);i++)
		fact[i] = (fact[i - 1] * i) % mod;
	for(int i = 1;i <= min(k,n);i++){
		ans += (C(n,i) * num(n - i,n)) % mod;
		ans %= mod;
	}
	printf("%lld",ans + 1);
}

Measured memory_bytes: 3328
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

int main()
{
    optimizeIO();

    int a,b;
    string s;

    cin>>a>>s>>b;

    if(s=="+") cout<<a+b<<endl;
    if(s=="-") cout<<a-b<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


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

int main(){
	int w=0;
	int h=0;
	int n=0;
	int s=0;
	int i=0;
	int x[1000];
	int y[1000];
	int a=0;
	int b=0;
	
	cin>>w;
	cin>>h;
	cin>>n;
	cin>>x[0];
	cin>>y[0];
	for(i=0;i<n-1;i++){
		cin>>x[i+1];
		cin>>y[i+1];
		if(x[i]==x[i+1]){
			if(y[i]>y[i+1]){
				s=s+y[i]-y[i+1];
			}else{
				s=s+y[i+1]-y[i];
			}
		}
		if(y[i]==y[i+1]){
			if(x[i]>x[i+1]){
				s=s+x[i]-x[i+1];
			}else{
				s=s+x[i+1]-x[i];
			}
		}
		a=x[i+1]-x[i];
		b=y[i+1]-y[i];
		if(a*b>0){
			if(a<0){
				a=-a;
				b=-b;
			}
			if(a>b){
				s=s+a;
			}else{
				s=s+b;
			}
		}
		if(a*b<0){
			if(a>b){
				b=-b;
			}else{
				a=-a;
			}
			s=s+a+b;
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9+1;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 4e5;
ll n, x, y, mama, mami=iinf, mima, mimi=iinf, c[N], zc;
map<ll, vl> m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> x >> y;
    if(x > y) swap(x, y);
    maxs(mama, y);
    mins(mami, y);
    maxs(mima, x);
    mins(mimi, x);
    m[x].pb(i);
    m[y].pb(i);
  }
  ll ans = iinf;
  zc = n;
  map<ll, vl>::iterator l=m.begin(), r=m.begin();
  while(r != m.end()){
    each(itr, r->se) if(++c[*itr] == 1) zc--;
    while(!zc){
      mins(ans, r->fi - l->fi);
      each(itr, l->se) if(--c[*itr] == 0) zc++;
      l++;
    }
    r++;
  }
  cout << min((mama-mami) * (mima-mimi), ans * (mama-mimi)) << endl;
  return 0;
}

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

int main() {
    int x, y, a, b;
    cin >> x >> y;
    a = 2 * x - y / 2;
    b = y / 2 - x;
    if (a >= 0 & b >= 0) {
        if ((x == a + b) & (y == a * 2 + b * 4)) {
            printf("%s\n", "Yes");
        } else {
            printf("%s\n", "No");
        }
    } else {
        printf("%s\n", "No");
    }

    return 0;
}


Measured memory_bytes: 3632
n=int(input())
a_list=list(map(int, input().split()))
multi_sum=1
LIMIT=1000000000000000000

if 0 not in a_list:
    for a_i in a_list:
        multi_sum*=a_i
        if multi_sum > LIMIT:
            multi_sum=-1
            break
else:
    multi_sum=0

print(multi_sum)



Measured memory_bytes: 21644
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
#define setzero(x) memset(x,0,sizeof(x))
  
using namespace std;
 
const int inf = 2e9+500;
const int N = 1e3+10;
const int bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 
    
    ld r;
    cin>>r;

    cout<<2.0*pi*r<<"\n";
    

}


Measured memory_bytes: 3808
package main

import (
        "bufio"
        "fmt"
        "os"
        "sort"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int64 {
        n, _ := strconv.ParseInt(str, 10, 64)
        return n
}

func intSprit(str string) []int64 {
        strs := strSprit(str)
        cols := make([]int64, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

type int64s []int64

func (s int64s) Len() int {
        return len(s)
}
func (s int64s) Less(i, j int) bool {
        return s[i] < s[j]
}
func (s int64s) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func main() {
        line := readBigLine()

        spln := intSprit(line)

        N := spln[0]
        x := spln[1]

        ln := readBigLine()
        a := intSprit(ln)

        sort.Sort(int64s(a))
        c := 0
        for i := int64(0); i < N; i++ {
                if x <= 0 {
                        break
                }
                if x-a[i] < 0 {
                        break
                }
                x -= a[i]
                c++
        }
        if c > 0 && x != 0 && c == int(N) {
                c--
        }
        fmt.Println(c)
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    ll k;
    string s;
    cin >> k >> s;
    ll n=s.size();
    for (ll i=0;i<min(k,n);i++){
        cout << s[i];
    }
    if (k<s.size()){
        cout << "...";
    }
    cout << endl;
    return 0;
}
 
 


Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<map>
#include<set>

int const MAXN = 2e5;
int a[MAXN], b[MAXN];
int c[MAXN-1], d[MAXN+MAXN-2];
int next_pos[MAXN];

int main() {
  int N; std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> a[i];
  for(int i = 0; i < N; ++i) std::cin >> b[i];
  for(int i = 0; i < N-1; ++i) c[i] = a[i]^a[i+1];
  for(int i = 0; i < 2*N-2; ++i) d[i] = b[i%N]^b[(i+1)%N];
  std::set<int> ans;
  // KMP
  int i = 1, j = 0;
  next_pos[1] = 0;
  while(i < N-1) {
    if(c[i] == c[j]) next_pos[++i] = ++j;
    else if(j == 0) next_pos[++i] = j;
    else j = next_pos[j];
  }
  i = j = 0;
  while(i < 2*N-2 && j < N-1) {
    if(d[i] == c[j]) { ++i; ++j; }
    else if(j == 0) ++i;
    else j = next_pos[j];
    if(j == N-1) {
      ans.insert((N+N-1-i)%N);
      --i; --j;
      j = next_pos[j];
    }
  }
  
  // ans
  for(auto k: ans) {
    int x = a[0]^b[(N-k)%N];
    std::cout << k << " " << x << std::endl;
  }
  return 0;
}



Measured memory_bytes: 17536
#include <iostream>
using namespace std;
int main() {
      int n,m,zec[100],j;
      cin >>n>>m;
      for(int i=1;i<=n;i++)cin>>zec[i];
      for(int i=1;i<=m;i++)for(j=1;j<n;j++)if(zec[j]%i>zec[j+1]%i)swap(zec[j+1],zec[j]);
      for(int i=1;i<=n;i++)cout<<zec[i]<<endl;
}

Measured memory_bytes: 3112
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	
	vector<vector<int>> sw(N, vector<int>());
	vector<int> p;

	for (int i = 0; i < M; i++)
	{
		int k;
		cin >> k;

		for (int j = 0; j < k; j++)
		{
			int s;
			cin >> s;

			sw[s-1].emplace_back(i);
		}
	}

	for (int i = 0; i < M; i++)
	{
		int j;
		cin >> j;

		p.emplace_back(j);
	}

	int light[10];
	int count = 0;

	for (int i = 0; i < pow(2, N); i++)
	{
		memset(light, 0, M * sizeof(int));

		for (int j = 0; j < N; j++)
		{
			if ((i >> j) & 1)
			{
				for (int k = 0; k < sw[j].size(); k++)
				{
					light[sw[j][k]] ++;
				}
			}
		}

		bool flag = true;
		for (int j = 0; j < M; j++)
		{
			if (light[j] % 2 != p[j])
			{
				flag = false;
				break;
			}
		}

		if (flag)
		{
			count++;
		}
	}

	cout << count << endl;

	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N-1)
	for i := range A {
		A[i] = readInt() - 1
	}
	for i := range B {
		B[i] = readInt()
	}
	for i := range C {
		C[i] = readInt()
	}
	ans := B[A[0]]
	for i := 1; i < N; i++ {
		j := A[i]
		ans += B[j]
		if A[i-1] == j-1 {
			ans += C[j-1]
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
from math import ceil
from itertools import permutations

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
p = permutations([a, b, c, d, e])

ans = 643
for m in p:
    t = 0
    for i in range(4):
        t += m[i]
        t = ceil(t / 10) * 10
    t += m[4]
    if ans > t:
        ans = t

print(ans)

Measured memory_bytes: 3064
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, k; cin >> n >> k;
    VI a(n); cin >> a;
    SORT(a);
    int ans = 0;
    FOR(i, 0, k)ans += a[i];
    print(ans);

    return 0;
}

Measured memory_bytes: 3620
use std::io::Read;
struct Scanner<R> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader }
    }

    fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|r: Result<u8, std::io::Error>| -> char { r.unwrap() as char })
            .skip_while(|c: &char| -> bool { c.is_whitespace() })
            .take_while(|c: &char| -> bool { !c.is_whitespace() })
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
}

#[derive(Debug, Clone, PartialEq)]
struct Card {
    kind: char,
    number: u8,
}

impl std::str::FromStr for Card {
    type Err = String;
    fn from_str(s: &str) -> Result<Card, Self::Err> {
        Ok(Card {
            kind: s.chars().next().unwrap(),
            number: (&s[1..]).parse().unwrap(),
        })
    }
}

impl ToString for Card {
    fn to_string(&self) -> String {
        format!("{}{}", self.kind, self.number)
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|u| u.to_string())
            .collect::<Vec<String>>()
            .join(sep)
    }
}

use std::io;

fn bubble(v: &mut Vec<Card>) {
    for i in 0..v.len() {
        for j in (i + 1..v.len()).rev() {
            if v[j].number < v[j - 1].number {
                v.swap(j, j - 1);
            }
        }
    }
}

fn selection(v: &mut Vec<Card>) {
    for i in 0..v.len() {
        let mut min_idx = i;
        for j in i..v.len() {
            if v[j].number < v[min_idx].number {
                min_idx = j;
            }
        }
        v.swap(i, min_idx);
    }
}

fn is_stable(v1: &Vec<Card>, v2: &Vec<Card>) -> bool {
    v1.iter().zip(v2.iter()).all(|(c1,c2): (&Card, &Card)| -> bool { c1 == c2})
}

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin);

    let n: usize = sc.next();
    let mut v: Vec<Card> = (0..n).map(|_| sc.next()).collect();

    let mut selection_sorted = v.clone();
    selection(&mut selection_sorted);
    bubble(&mut v);

    let is_stable_v = is_stable(&v, &selection_sorted);
    println!("{}", v.into_iter().join(" "));
    println!("Stable");


    println!("{}", selection_sorted.into_iter().join(" "));
    println!("{}", if is_stable_v { "Stable" } else {"Not stable"});
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N+1),b(N+1);
    
    for(int i=1;i<=N;i++) cin>>a[i];
    for(int i=1;i<=N;i++) cin>>b[i];

    for(int i=2;i<=N;i++) a[i]+=a[i-1];
    for(int i=2;i<=N;i++) b[i]+=b[i-1];

    int ans=0;
    for(int i=1;i<=N;i++){
        int cnt=a[i]+b[N]-b[i-1];
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[500000];
int M[100050][26][26], PF[100050];

struct trie {
  int nxt[26], num, id;
  trie() { fill(nxt, nxt + 26, -1); num = 0; id = -1; }
} T[500000];
int tnum = 1, troot = 0;
int alloc() {
  return tnum++;
}

void trie_add(char* s, int id) {
  int p = troot;
  for (int i = 0; s[i]; ++i) {
    int c = s[i] - 'a';
    ++T[p].num;
    if (T[p].nxt[c] == -1) {
      T[p].nxt[c] = alloc();
    }
    p = T[p].nxt[c];
  }
  ++T[p].num;
  T[p].id = id;
}

int CM[26][26];

void trie_precalc(int p, int pf) {
  if (T[p].id >= 0) {
    PF[T[p].id] = pf;
    memcpy(M[T[p].id], CM, sizeof(CM));
    ++pf;
  }
  for (int i = 0; i < 26; ++i) {
    if (T[p].nxt[i] >= 0) {
      for (int j = 0; j < 26; ++j) {
        if (i != j && T[p].nxt[j] >= 0) {
          CM[i][j] += T[T[p].nxt[j]].num;
        }
      }
      trie_precalc(T[p].nxt[i], pf);
      for (int j = 0; j < 26; ++j) {
        if (i != j && T[p].nxt[j] >= 0) {
          CM[i][j] -= T[T[p].nxt[j]].num;
        }
      }
    }
  }
}

int main() {
  int N = in();
  for (int i = 0; i < N; ++i) {
    scanf("%s", S);
    trie_add(S, i);
  }

  trie_precalc(troot, 0);

  int Q = in();
  char A[32];
  int O[32];
  for (int i = 0; i < Q; ++i) {
    int k = in() - 1;
    scanf("%s", A);
    for (int j = 0; j < 26; ++j) {
      O[A[j] - 'a'] = j;
    }
    int res = 1 + PF[k];
    for (int a = 0; a < 26; ++a) {
      for (int b = 0; b < 26; ++b) {
        if (a != b && O[a] > O[b]) {
          res += M[k][a][b];
        }
      }
    }
    printf("%d\n", res);
  }

  return 0;
}


Measured memory_bytes: 320000
#include<stdio.h>

int main()
{
    int a[10], b[100] = {0}, bingo=0, x;
    scanf("%d%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&x);
    for(int i=0;i<x;i++){
        scanf("%d",&b[i]);
    }
    for(int i = 0; i<x;i++){
        for(int j=0;j<9;j++){
            if(b[i]==a[j]){
                a[j]=101;
            }
        }
    }
   if(a[0]==101&&a[1]==101&&a[2]==101){
       bingo++;
   }else if(a[3]==101&&a[4]==101&&a[5]==101){
       bingo++;
   }else if(a[6]==101&&a[7]==101&&a[8]==101){
       bingo++;
   }else if(a[0]==101&&a[3]==101&&a[6]==101){
       bingo++;
   }else if(a[1]==101&&a[4]==101&&a[7]==101){
       bingo++;
   }else if(a[2]==101&&a[5]==101&&a[8]==101){
       bingo++;
   }else if(a[0]==101&&a[4]==101&&a[8]==101){
       bingo++;
   }else if(a[2]==101&&a[4]==101&&a[6]==101){
       bingo++;
   }
   bingo>0?printf("Yes\n"):printf("No\n");
return 0;
}

Measured memory_bytes: 1580
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;

ll MOD = 998244353;

int main(){
    int N,K;cin>>N>>K;
    vector<int> starts;
    vector<int> ends;
    for(int i = 0;i < K;i++){
        int l,r;cin>>l>>r;
        starts.push_back(l);
        ends.push_back(r);
    }
    vector<ll> dp(N+1,0);
    vector<int> ok(N+1,0);
    ok[0]=1;
    dp[0] = 1;
    dp[1]=-1;
    ok[1] = -1;
    for(int i = 0;i < N;i++){
        if(i != 0)ok[i]+=ok[i-1];
        if(i != 0){
            dp[i] += dp[i-1];
            dp[i] %= MOD;
        }
        if(ok[i] == 0)continue;
        for(int j = 0;j < K;j++){
            int s = starts[j];
            int e = ends[j];
            if(i+s >= N)continue;
            dp[i+s] +=dp[i];
            dp[i+s] %= MOD;
            ok[i+s]++;
            ok[min(i+e+1,N)]--;
            dp[min(i+e+1,N)]-=dp[i];
            dp[min(i+e+1,N)] += MOD;
            dp[min(i+e+1,N)] %= MOD;
        }
    }
    // for(int i = 0;i < N;i++){
    //     cout<<dp[i]<<endl;
    // }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 5556
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let a: Vec<usize> = read_as_vec();

    let mut x: Vec<usize> = vec![0;n];

    let mut x0: usize = a.iter().sum();

    let mut i = 1;

    while i < n{
        x0 -= 2*a[i];
        i += 2;
    }

    x[0] = x0;

    for i in 1..n{
        x[i] = 2*a[i-1] - x[i-1];
    }

    for elem in x{
        print!("{} ", elem);
    }
    println!("");
 }


Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    string s;
    int k;
    cin >> s >> k;
    k--;
    int x = 0;
    rep(i, (int)s.size()) {
        if (s[i] != '1') {
            x = i;
            break;
        }
    }
    if (x <= k) cout << s[x] << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3604
import copy
def main():
    s=list(input())
    n=len(s)
    ans=n
    p=0
    look=[chr(i) for i in range(97, 97+26)]
    for i in look:
        t=copy.copy(s)
        cnt=0
        check=0
        while True:
            key=0
            for j in range(len(t)-1):
                if t[j]==i:
                    continue
                else:
                    check=1
                    if t[j+1]==i:
                        t[j]=i
                    key=1
                    p=1
            if check==0:
                ans=0
                break
            if len(t)>0 and t[len(t)-1]!=i:
                key=1
                check=1
            t.pop(len(t)-1)
            if key==0:
                break
            cnt+=1
            if t==[]:
                break
        if p!=0 and cnt!=0:
            ans=min(ans,cnt)
    print(ans)    
main()

Measured memory_bytes: 39664