akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
const long long int inf =-1e18;
vector<long long int>dp;
vector<long long int>pre;

void f(int mask,const vector<int>&nt,int i,long long int tempans,int group){
    if(i==nt.size()){
        dp[mask]=max(dp[mask],tempans+pre[group]);
        return;
    }
    f(mask,nt,i+1,tempans,group);
    f(mask^(1<<nt[i]),nt,i+1,tempans,group^(1<<nt[i]));
    return;
}

int main() {
	int n;
	scanf("%d",&n);
	dp=vector<long long int>(1<<n,inf);
	vector<vector<int>>matrix(n,vector<int>(n));
	for(int i=0;i<n;i+=1){
	    for(int j=0;j<n;j+=1){
	        scanf("%d",&matrix[i][j]);
	    }
	}
	pre.resize(1<<n);
	for(int m=0;m<(1<<n);m+=1){
	    for(int i=0;i<n;i+=1){
	        if(m&(1<<i)){
	            for(int j=i+1;j<n;j+=1){
	                if(m&(1<<j)){
	                    pre[m]+=matrix[i][j];
	                }
	            }
	        }
	    }
	}
	dp[0]=0;
	for(int m=0;m<(1<<n);m+=1){
	    vector<int>nt;
	    for(int i=0;i<n;i+=1){
	        if(!(m&(1<<i))){
	            nt.push_back(i);
	        }
	    }
	    f(m,nt,0,dp[m],0);
	}
	printf("%lld",dp[(1<<n)-1]);
	return 0;
}


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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];


bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ll n;
    // cin >> n;/
    string str1,str2;
    cin >> str1 >> str2;
    ll flag1 = 0;
    if(str2.size() - str1.size() == 1)
    {
        for(ll i = 0; i<str1.size();i++)
        {
            if(str1[i]!=str2[i])
            {
                flag1 = 1;
                break;
            }
        }
        if(flag1 == 1)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
        
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}   

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

vector<int> topologicalSort(const vector<vector<int> > &graph) {
    int V = (int)graph.size(), cur = 0;
    vector<int> deg(V), res(V);
    stack<int> stk;
    for (int i = 0; i < V; ++i)
        for (int v : graph[i])deg[v]++;
    for (int i = 0; i < V; ++i)if (deg[i] == 0)stk.push(i);
    while (!stk.empty()) {
        int v = stk.top(); stk.pop();
        res[cur++] = v;
        for (int w : graph[v])if (!--deg[w])stk.push(w);
    }
    return cur == V ? res : vector<int>();
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vi> G(N);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
    }
    vi ts = topologicalSort(G);

    vi dp(N);
    each(u, ts) {
        each(v, G[u]) {
            smax(dp[v], dp[u] + 1);
        }
    }
    cout << *max_element(all(dp)) << endl;
}

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


Measured memory_bytes: 6912
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

w , h = gi
a1 = h / 3
a2 = h / 3
a2 += 1 if h % 3 != 0
ans = a2*w-a1*w

a1 = w / 3
a2 = w / 3
a2 += 1 if w % 3 != 0
d = a2*h-a1*h
ans = d if ans > d

rep h-1 do |i|
a = (i+1)*w
b = (h-i-1)*(w/2)
c = (h-i-1)*(w/2+w%2)
ma = max max(a,b), max(a,c)
mi = min min(a,b), min(a,c)
d = ma - mi

ans = d if ans > d
end

rep w-1 do |i|
a = (i+1)*h
b = (w-i-1)*(h/2)
c = (w-i-1)*(h/2+h%2)
ma = max max(a,b), max(a,c)
mi = min min(a,b), min(a,c)
d = ma - mi

ans = d if ans > d
end

puts ans

Measured memory_bytes: 2300
#include <iostream>

using namespace std;

int main()

{
    int a, b;

    cin >> a >> b;

    if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0)

        cout << "Possible";

    else

        cout << "Impossible";

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
K,N = map(int,input().split())	
li = list(map(int,input().split()))	
le = []
for i in range(N):
    if i==N-1:
        le.append(K-li[i]+li[0])
    else: 
        le.append(li[i+1]-li[i])
print(sum(le)-max(le))


Measured memory_bytes: 26444
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    vector<ll> ans(s.size()+1);
    rep(i, s.size()+1)ans[i] = -1;

    rep(i, s.size()){
        if(s[i] == '>')continue;
        if(ans[i]<0)ans[i]=0, ans[i+1]=1;
        else ans[i+1] = ans[i]+1;
    }
    // rep(i, s.size())cout << ans[i] << s[i];cout << ans.back() << endl;
    for(ll i = s.size()-1; i >= 0; i--){
        if(s[i]=='<')continue;
        if(ans[i+1]<0)ans[i+1]=0, ans[i]=1;
        else if(s[i-1]=='<')ans[i] = max(ans[i-1], ans[i+1])+1;
        else ans[i] = ans[i+1]+1;
    }
    // rep(i, s.size())cout << ans[i] << s[i];cout << ans.back() << endl;
    ll sum = 0;
    rep(i, ans.size())sum+=ans[i];
    cout << sum << endl;
}

Measured memory_bytes: 4740
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

typedef pair<LL, int> P;

int main() {
  priority_queue<P>  que;
  LL X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  for (int i = 0; i < A; ++i) {
    LL p; cin >> p;
    que.push({p, 1});
  }
  for (int i = 0; i < B; ++i) {
    LL p; cin >> p;
    que.push({p, 2});
  }
  for (int i = 0; i < C; ++i) {
    LL p; cin >> p;
    que.push({p, 0});
  }

  LL sum = 0;
  int N = 0;
  while ((X + Y - N) > 0) {
    auto p = que.top(); que.pop();
    if (p.second == 1) {
      if (X <= 0) continue;
      sum += p.first;
      --X;
    } else if (p.second == 2) {
      if (Y <= 0) continue;
      sum += p.first;
      --Y;
    } else {
      sum += p.first;
      ++N;
    }
  }
  cout << sum << endl;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, k, s; cin >> n >> k >> s;
  if(s == 1000000000)
  {
    vll a(n, 1000000000 - 1);
    rep(i, k) a[i] = s;
    rep(i, n) cout << a[i] << " ";
    cout << endl;
  }
  else
  {
    vll a(n, 1000000000);
    rep(i, k) a[i] = s;
    rep(i, n) cout << a[i] << " ";
    cout << endl;
  }
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 2176
N=int(input())
slist=[x=="o" for x in input()]
#print(slist)

answer_list=[0]*N

ok=False
for p1,p2 in [(1,1),(1,-1),(-1,1),(-1,-1)]:
  answer_list[0]=p1
  answer_list[1]=p2
  
  for i in range(2,N):
    if answer_list[i-1]==1:
      if slist[i-1]:
        answer_list[i]=answer_list[i-2]
      else:
        answer_list[i]=-answer_list[i-2]
    else:
      if slist[i-1]:
        answer_list[i]=-answer_list[i-2]
      else:
        answer_list[i]=answer_list[i-2]
        
  contra=False
  for i in range(N):
    l=(i-1)%N
    r=(i+1)%N
    if answer_list[i]==1:
      if slist[i]:
        if answer_list[l]!=answer_list[r]:
          contra=True
      else:
        if answer_list[l]==answer_list[r]:
          contra=True
    else:
      if slist[i]:
        if answer_list[l]==answer_list[r]:          
          contra=True
      else:
        if answer_list[l]!=answer_list[r]:
          contra=True

  if not contra:
    ok=True
    break
    
if ok:
  sw_list=[]
  for ans in answer_list:
    if ans==1:
      sw_list.append("S")
    else:
      sw_list.append("W")
  print("".join(sw_list))
else:
  print(-1)

Measured memory_bytes: 5784
r,g,b,n=map(int,input().split())
rm=n//r
count=0
for i in range(rm+1):
    rn=n-r*i
    gm=rn//g
    for j in range(gm+1):
        rn1=rn-g*j
        if rn1%b==0:
            count=count+1
print(count)

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";

int quickPow(int x, int n) {
    if (n == 0) {
        return 1;
    }

    int t = quickPow(x, n / 2);
    (t *= t) %= mod;

    if (n % 2 == 0) {
        return t;
    }
    return ((t * x) % mod);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n;
    cin >> n;

    int sum = 0, sumsqr = 0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        (sum += a) %= mod;
        (sumsqr += (a * a)) %= mod;
    }

    cout << ((((sum * sum - sumsqr + mod) % mod) * quickPow(2, mod - 2)) % mod) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 3620
from fractions import gcd
def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

print(len(prime_factorize_dict(gcd(*map(int, input().split())))) + 1)


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

int main(){
  int N,X,Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> ans(N,0);
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int dis=0;
      if(i<=X && Y<=j) dis = (X-i)+(j-Y)+1;
      else if(i<=X && j<Y) dis = min(j-i,(X-i)+(Y-j)+1);
      else if(X<i && Y<=j) dis = min(j-i,(j-Y)+(i-X)+1);
      else if(X<i && j<Y) dis = min(j-i,(i-X)+(Y-j)+1);
      else dis = j-i;
      ans[dis]++;
    }
  }
  
  for(int k=1;k<=N-1;k++) cout << ans[k] << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
G = [[1]*N for i in range(N)]
R = N*(N-1)//2
for i in range(N):
    G[i][i] = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        if K > 0:
            G[i][j] = G[j][i] = 0
            K -= 1
            R -= 1
if K > 0:
    print(-1)
else:
    print(R)
    for i in range(N):
        for j in range(i+1, N):
            if G[i][j]:
                print(i+1, j+1)

Measured memory_bytes: 3700
package main

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

var mod = int(1e9) + 7

func main() {
	n, k := readInt(), readInt()

	l, r := (k-1)*k/2, (n-k+1+n)*k/2
	ans := r - l + 1
	for i := k + 1; i <= n+1; i++ {
		l, r = (i-1)*i/2, (n-i+1+n)*i/2
		ans += r - l + 1
		ans %= mod
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

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

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	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 min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1752
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N;
    int[] W;
    private void solve() {
        N = nextInt();
        W = new int[N];

        int S = 0;
        for(int i = 0;i < N;i++) {
            W[i] = nextInt();
            S += W[i];
        }

        int ans = Integer.MAX_VALUE;
        for(int i = 0;i < N - 1;i++) {
            int tmpS = 0;
            for(int j = 0;j <= i;j++) {
                tmpS += W[j];
            }

            ans = Math.min(ans, Math.abs((S - tmpS) - tmpS));
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

typedef long long ll;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)

const int N=200+5,L=60,T=N*L,D=1e9+7;
const ll inf=1e18+5;
int n;
ll a[N];
struct State
{
ll a[N],l,r;
State () =default ;
State (ll *na,const ll &k)
{
	ll mn=na[1];
	rep(i,2,n)chmin(mn,na[i]);
	rep(i,1,n)a[i]=na[i]-mn;
	r=mn;l=max(0LL,mn-k);
}
};
bool operator <(const State &a,const State &b)
{
	rep(i,1,n)
	if(a.a[i]!=b.a[i])return a.a[i]<b.a[i];
	if(a.l!=b.l)return a.l<b.l;
	return a.r<b.r;
}
bool operator ==(const State &a,const State &b)
{
	rep(i,1,n)
	if(a.a[i]!=b.a[i])return 0;
	return 1;
}
vector<State>state;
pair<ll,int>q[N];
ll na[N];

ll min_cost(const ll &l,const ll &r)//x>=l,x<=r,min_number_of_1_of_x
{
	if(l>r)return inf;
	int ans=0;
	per(j,L-1,0)
	{
		if(((l>>j)&1)!=((r>>j)&1))
		{
			if(l&((1LL<<j)-1))++ans;
			break;
		}
		if((l>>j)&1)++ans;
	}
	return ans;
}
void check(const ll &k)
{
	if(k<0)return ;
	state.push_back(State(na,k));
}
namespace solve_state
{
int main()
{
	sort(state.begin(),state.end());
	ll ans=0;
	for(auto l=state.begin();l<state.end();)
	{
		auto r=l;
		ll nr=-1;
//		rep(i,1,n)cerr<<l->a[i]<<" ";cerr<<endl;
		while(r<state.end()&&*l==*r)
		{
//			cerr<<r->l<<" "<<r->r<<endl;
			if(r->l>nr)
			{
				(ans+=(r->r)-(r->l)+1)%=D;
				nr=r->r;
			}
			else
			if(r->r>nr)
			{
				(ans+=(r->r)-nr)%=D;
				nr=r->r;
			}
			++r;
		}
//		cerr<<ans<<endl;
		l=r;
	}
	return ans;
}
};

int main()
{
	//freopen("1.in","r",stdin);
	ll k;
	cin>>n>>k;
	rep(i,1,n)cin>>a[i];
	rep(j,0,L)
	{
		rep(i,1,n)q[i]=make_pair(a[i]&((1LL<<j)-1),i);
		sort(q+1,q+n+1);
		rep(i,1,n)na[i]=a[i]>>j;
		check(k-j-min_cost(0,q[1].first));
		q[n+1].first=(1LL<<j)-1;
		rep(i,1,n)
		{
			if(--na[q[i].second]<0)break;
			check(k-j-min_cost(q[i].first+1,q[i+1].first));
		}
	}
	cout<<solve_state::main()<<endl;
}


Measured memory_bytes: 28844
#include <iostream>

using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;
    int as[n] = { 0 };
    int bs[n] = { false };
    for (size_t i = 0; i < m; ++i) {
        size_t a, b;
        cin >> a >> b;
        if (a == 1) { as[b - 1] = true ; }
        if (b == n) { bs[a - 1] = true ; }
    }
    for (size_t i = 1; i < n; ++i) {
        if (as[i] && bs[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int left(int i) {
	return i * 2;
}
int right(int i) {
	return i * 2 + 1;
}
int parent(int i) {
	return i / 2;
}

int A[500100] = { 0 };
int h;

void maxHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int largest;
	if (l <= h && A[i] < A[l])
		largest = l;
	else
		largest = i;
	if (r <= h && A[largest] < A[r])
		largest = r;
	if (largest != i) {
		swap(A[largest], A[i]);
		maxHeapify(largest);
	}
}

void buildMaxHeap() {
	for (int i = h / 2; i >= 1; i--) {
		maxHeapify(i);
	}
}
signed main() {
	int i;
	cin >> h;
	rep(i, h) cin >> A[i + 1];
	buildMaxHeap();
	rep(i,h) {
		cout << ' ' << A[i + 1];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 7000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		int[,] csum = new int[2,N+1];
		for(int i = 0; i < 2; i++)
		{
			string[] args = Console.ReadLine().Split(' ');
			for(int j = 1; j <= N; j++)
				csum[i,j] = csum[i,j-1] + Int32.Parse(args[j-1]);
		}

		int ans = 0;
		for(int i = 1; i <= N; i++)
			ans = Math.Max(ans, csum[0,i] + csum[1,N] - csum[1,i-1]);

		Console.WriteLine(ans);
	}
}





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

int main()
{
	int S ;
	const int MOD = 1e9+7 ;
	cin >> S ;

	if(S < 3)
	{
		cout << 0 << '\n' ;
		return 0 ;
	}
	
	vector<int> dp(S+1, 1) ;
	for(int i = 4; i <= S; ++i)
	{
		for(int term = 3; term <= i; ++term)
		{
			if(i-term >= 3)
				dp[i] = (dp[i] + dp[i-term]) % MOD ;
		}
	}	
	cout << dp[S] << '\n' ;
}


Measured memory_bytes: 3612
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    long s = aryread().sum();
    if(s <= n)
        writeln(n - s);
    else
        writeln(-1);
}

bool is_exist(string s, char c)
{
    return (s.countUntil(c) >= 0);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2916
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; ll l; cin >> n >> l;
  vector<int> a{-1}, b{-1};
  while (n--) {
    string s; cin >> s;
    int pos = 0;
    for (char c : s) {
      if (c == '0') {
        if (a[pos] == -1) {
          int nx = a.size();
          a.emplace_back(-1);
          b.emplace_back(-1);
          a[pos] = nx;
          pos = nx;
        } else {
          pos = a[pos];
        }
      } else if (c == '1') {
        if (b[pos] == -1) {
          int nx = a.size();
          a.emplace_back(-1);
          b.emplace_back(-1);
          b[pos] = nx;
          pos = nx;
        } else {
          pos = b[pos];
        }
      }
    }
  }
  vector que{0};
  map<ll, int> cnt;
  for (int len = 0; len < l && !que.empty(); ++len) {
    vector<int> nx;
    for (int e : que) {
      if (a[e] >= 0 || b[e] >= 0) {
        if (a[e] == -1 || b[e] == -1) ++cnt[l - len];
        if (a[e] != -1) nx.emplace_back(a[e]);
        if (b[e] != -1) nx.emplace_back(b[e]);
      }
    }
    que.swap(nx);
  }
  ll x = 0;
  for (auto [h, num] : cnt) {
    if (num & 1) {
      ll gru = 1, tmp = h;
      while (tmp % 2 == 0) {
        gru <<= 1;
        tmp >>= 1;
      }
      x ^= gru;
    }
  }
  cout << (x == 0 ? "Bob\n" : "Alice\n");
  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char> > a(h, vector<char>(w));

  queue<pii> qu;
  int nokori = h * w;
  rep (i, h) {
    rep (j, w) {
      char c;
      cin >> c;
      a[i][j] = c;
      if (c == '#') {
        nokori--;
        qu.push(pii(i, j));
      }
    }
  }

  int ans = 0;
  for (ans = 0;; ans++) {
    if (nokori == 0) break;
    queue<pii> qu2;
    while (!qu.empty()) {
      int i0 = qu.front().first, j0 = qu.front().second;
      qu.pop();
      rep (k, 4) {
        int ni = i0 + dx[k], nj = j0 + dy[k];
        if (!in(ni, 0, h) || !in(nj, 0, w)) continue;
        if (a[ni][nj] == '.') {
          a[ni][nj] = '#';
          nokori--;
          qu2.push(pii(ni, nj));
        }
      }
    }
    qu = qu2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9600
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var x = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        if (n == 1) { Console.WriteLine(Math.Abs(x - a[0])); goto end; }
        var ans = Gcd(Math.Abs(a[0] - x), Math.Abs(a[1] - x));
        for (int i = 2; i < n; i++)
            ans = Gcd(ans, Math.Abs(a[i] - x));
        Console.WriteLine(ans);
        end:;
    }
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}


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

int N;
vector<int> p;
vector<vector<int>> c;
vector<int> a, a_inv;
vector<int> a_sub;
vector<int> is_confirm, is_leaf, is_progeny, progeny_count, candidate_v;

int do_confirm(){
	for(int i = N - 1; i >= 0; i--){
		int count = 0;
		for(int j = 0; j < c[i].size(); j++){
			count += is_confirm[c[i][j]];
		}
		if(count == c[i].size()){
			is_leaf[i] = 1;
			if(a[i] == i){
				is_confirm[i] = 1;
			}
		}
	}
	return is_confirm[0];
}

void dfs(int a_v){
	if(is_confirm[a_v] == 0){
		is_progeny[a_inv[a_v]] = 1;
		if(is_leaf[a_v] == 0){
			for(int i = 0; i < c[a_v].size(); i++){
				dfs(c[a_v][i]);
			}
		}
	}
}

int decide(){
	if(is_leaf[a[0]] == 1){
		return a[0];
	}
	for(int i = 0; i < N; i++){
		is_progeny[i] = 0;
		progeny_count[i] = 0;
	}
	dfs(a[0]);
	for(int i = N - 1; i > 0; i--){
		progeny_count[i] += is_progeny[i];
		progeny_count[p[i]] += progeny_count[i];
	}
/*	printf("is_progeny:");
	for(int i = 0; i < N; i++){
		printf("%d ", is_progeny[i]);
	}
	printf("\n");
	printf("progeny_count:");
	for(int i = 0; i < N; i++){
		printf("%d ", progeny_count[i]);
	}
	printf("\n");
*/	candidate_v.assign(0, -1);
	for(int i = 1; i < N; i++){
		if(is_progeny[i] == 1 && progeny_count[i] == 1){
			candidate_v.push_back(i);
		}
	}
//	return candidate_v[0];
	return candidate_v[rand() % candidate_v.size()];
}

void insersion(int v){
	int V = v;
	for(; v >= 0; v = p[v]){
		a_sub[v] = a[v];
	}
	for(v = V; v > 0; v = p[v]){
		a[p[v]] = a_sub[v];
	}
	a[V] = a_sub[0];
	for(v = V; v >= 0; v = p[v]){
		a_inv[a[v]] = v;
	}
}

int main(){
//	srand((unsigned)time(NULL));
	int i;
	scanf("%d", &N);
	p.assign(N, -1);
	c.assign(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%d", &p[i]);
//		p[i] = rand() % i;
//		printf("p[%d] = %d\n", i, p[i]);
		c[p[i]].push_back(i);
	}
	a.assign(N, 0);
	a_inv.assign(N, 0);
	a_sub.assign(N, 0);
/*	for(i = 0; i < N; i++){
		a[i] = i;
		swap(a[i], a[rand() % (i + 1)]);
	}
*/	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		a_inv[a[i]] = i;
	}
	is_confirm.assign(N, 0);
	is_leaf.assign(N, 0);
	is_progeny.assign(N, 0);
	progeny_count.assign(N, 0);
	vector<int> ans(0);
	while(do_confirm() == 0){
/*		printf("a:");
		for(i = 0; i < N; i++){
			printf("%d ", a[i]);
		}
		printf("\n");
		printf("a_inv:");
		for(i = 0; i < N; i++){
			printf("%d ", a_inv[i]);
		}
		printf("\n");
		printf("is_confirm:");
		for(i = 0; i < N; i++){
			printf("%d ", is_confirm[i]);
		}
		printf("\n");
		printf("is_leaf:");
		for(i = 0; i < N; i++){
			printf("%d ", is_leaf[i]);
		}
		printf("\n");
*/		int v = decide();
//		printf("v = %d\n", v);
		ans.push_back(v);
		insersion(v);
//		printf("\n");
	}
	printf("%d\n", ans.size());
/*	if(ans.size() > 8000){
		return 0;
	}
*/	for(i = 0; i < ans.size(); i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define pb(x) push_back(x)
#define fi first
#define se second
#define mp(x,y) make_pair(x,y);

/*struct comp
{
    bool operator()()
    {
        
    }
};*/

int32_t main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
      int N,K;
      cin>>N>>K;
      vector<int>A(N+1,0);
      int cnt=N;
      for(int i=0;i<K;i++)
      {
          int d;
          cin>>d;
          for(int j=0;j<d;j++)
          {
              int y;
              cin>>y;
              A[y]++;
              if(A[y]==1) cnt--;
          }
      }
      
      cout<<cnt;
      
      cout<<endl;  
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool ans;
    if(abs(a-b) <= (v-w)*t) ans = true;
    else ans = false;
    cout << (ans ? "YES" : "NO") << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3648
package main

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

func main() {
	n := readInt()
	a := make(sortArray, n)
	for i := range a {
		a[i].x = readInt()
		a[i].i = i + 1
	}
	sort.Sort(a)

	for i := range a {
		fmt.Println(a[i].i)
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
	i int
}

type sortArray []xxx

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

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	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 min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 4224
fun main(args: Array<String>) {
    val s = readLine()!!
    var left = 0
    var right = 1
    val ansArray = Array(s.length) { 0 }
    while (true) {
        var a = 0
        var b = 0
        while (right < s.length && (s[right - 1] != 'L' || s[right] != 'R')) {
            if (s[right - 1] == 'R' && s[right] == 'L' ) {
                a = right - 1
                b = right
            }
            right++
        }

        if (right > s.length) {
            break
        }

        ansArray[a] = (a - left) / 2 + (right - a - 1) / 2 + 1
        ansArray[b] = (b - left) / 2 + (right - b - 1) / 2 + 1
        left = right
        right++
    }
    println(ansArray.joinToString(" "))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 39308
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll h,w;
 cin>>h>>w;
 if( h == 1 || w == 1 ) cout<<1<<endl;
 else cout<< ( (h/2)*(w/2)) + ( (h-h/2) * (w-w/2))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int e, y;
	
	scanf( "%d %d", &e, &y );
	switch( e )
	{
		case 0:
			if( y <= 1911 )
			{
				printf( "M%d\n", y - 1868 +1 );
			}
			else if( y <= 1925 )
			{
				printf( "T%d\n", y - 1912 +1 );
			}
			else if( y <= 1988 )
			{
				printf( "S%d\n", y - 1926 +1 );
			}
			else
			{
				printf( "H%d\n", y - 1989 +1 );
			}
			break;
		case 1:
			printf( "%d\n", y + 1868 -1 );
			break;
		case 2:
			printf( "%d\n", y + 1912 -1 );
			break;
		case 3:
			printf( "%d\n", y + 1926 -1 );
			break;
		case 4:
			printf( "%d\n", y + 1989 -1 );
			break;
	}
	return 0;
}



Measured memory_bytes: 2100
char buf[2000000];
sz;
main()
{
	read(0,buf,2000000);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	int now=1;
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		now+=A==now;
	}
	printf("%d\n",now==1?-1:N-now+1);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  vll A(N + 1);
  rep(i, N + 1) {
    cin >> A[i];
  }

  vll B(N);
  rep(i, N) {
    cin >> B[i];
  }
  ll ans = 0;
  rep(i, N) {
    ll l = A[i];
    ll b = B[i];

    if (l <= b) {
      ans += l;
      b -= l;
    } else {
      ans += b;
      b = 0;
    }

    ll r = A[i + 1];
    if (r <= b) {
      ans += r;
      A[i + 1] = 0;
    } else {
      ans += b;
      A[i + 1] -= b;
    }
  }

  COUT(ans);

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int n,j,num;
	for(;scanf("%d",&n)!=EOF;){
		for(j=0,num=1;j<10;j++,num*=2){
			if(n%2){
				if(n==1)printf("%d",num);
				else printf("%d ",num);
			}
			n/=2;
		}
		printf("\n");
	}
	exit(0);
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define inf 0x3f3f3f3f
#define PI acos(double(-1))
using namespace std;

typedef long long ll;
const int maxn=2e5+10;
int n,t[maxn],T;
ll sum;

int main()
{
    scanf("%d%d",&n,&T);
    sum+=T;
    int a;
    int l;
    int a0;
    l=T;
    scanf("%d",&a0);
    for(int i=0;i<n-1;i++)
    {
       // int a;
        scanf("%d",&a);
        if(a>l)
        {
            sum=sum+T;
            l=a+T;
        }
        else{
            sum=sum+a-a0;
            l=a+T;
        }
        a0=a;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
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)*}
    };
}

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)*}
    };
}

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! {
        k: usize,
        s: usize,
    }
    let mut ans: usize = 0;
    for x in 0..k + 1 {
        if x > s {
            break;
        }
        if (x + k * 2) < s {
            continue;
        }
        let mut max: usize = k;
        let mut min: usize = 0;
        if (s - x) < k {
            max = s - x;
        }
        if (x + k) < s {
            min = s - x - k;
        }
        ans = ans + (max - min) + 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
h, n = map(int, input().split())
p = [0] * n
c = [0] * n

inf = 1e9 + 1

for i in range(n):
    pp, cc = map(int, input().split())
    p[i] = pp
    c[i] = cc
    
dp = [inf] * (h + max(p))
dp[0] = 0

for i in range(n):
    for j in range(h):
        dp[j + p[i]] = min(dp[j + p[i]], dp[j] + c[i])
    
print(min(dp[h:]))


Measured memory_bytes: 49244
n=int(input())
a=[True]*55556
b=[]
a[0]=a[1]=False
p=0
for i in range(2,55556):
	if a[i]:
		b.append(i)
		for j in range(2*i,55556,i):
			a[j]=False
i=cnt=0
ans=[]
while cnt<n:
	if b[i]%5==3:
		ans.append(b[i])
		cnt+=1
	i+=1
print(*ans)



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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

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

  cout << n/2+n%2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

/*	Segment Tree Template	*/

template <typename T> class SegTree{
	public:
	ll n;
	T *tree;
	T queryBase;
	T segOp(const T &left, const T &right);
	SegTree(ll len, T *arr, T qb){
		tie(n, queryBase) = tie(len, qb);
		tree = new T[4*n];
		for(ll i = 0; i < 4*n; i++)	tree[i] = queryBase;
		build(1, 0, n-1, arr);
	}
	T build(ll i, ll l, ll r, T *arr){
		if(l == r)	return tree[i] = arr[l];
		return tree[i] = segOp(build(i<<1, l, (l+r)>>1, arr), build(i<<1|1, ((l+r)>>1)+1, r, arr));
	}
	T update(ll i, const T &value, ll p = 1, ll l = 0, ll r = -1){
		if(r == -1)	r = n-1;
		if(l == r)	return tree[p] = value;
		ll m = (l+r)>>1;
		if(i <= m)	update(i, value, p<<1, l, m);	else update(i, value, p<<1|1, m+1, r);
		return tree[p] = segOp(tree[p<<1], tree[p<<1|1]);
	}
	T query(ll l, ll r, ll p = 1, ll tl = 0, ll tr = -1){
		if(tr == -1)	tr = n-1;
		if(l > r)	return queryBase;	// Overflow
		if(l == tl && r == tr)	return tree[p];	// Complete overlap
		ll m = (tl+tr)>>1;
		return segOp(query(l, min(m, r), p<<1, tl, m), query(max(l, m+1), r, p<<1|1, m+1, tr));
	}
};
template <typename T> T SegTree<T>::segOp(const T &left, const T &right){
	return max(left, right);
}

/*	Template Closure	*/

int main(){
	ll n;	cin>>n;
	ll a[n], h[n];	get(h, n);	get(a, n);
	pll b[n];	for(ll i = 0; i < n; i++)	b[i] = {h[i], i};
	sort(b, b+n);
	ll lis[n] = {0};
	SegTree<ll> s(n, lis, 0);
	for(auto x : b){
		lis[x.second] = s.query(0, x.second-1) + a[x.second];
		s.update(x.second, lis[x.second]);
	}
	cout<<*max_element(lis, lis+n);
}

Measured memory_bytes: 17712
def resolve():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    import itertools
    all = list(itertools.permutations(range(1, N + 1)))
    ans = all.index(P) - all.index(Q)
    print(abs(ans))

    return
resolve()

Measured memory_bytes: 8052