akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;


#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

	
//////////////////////////////code//////////////////////////////


int n;

vi arr;

int dp[3001][3001][2];

int sol(int i,int j,int k)
{
    if(i > j)
    return 0;
    
    
    if(dp[i][j][k]!=-1)
    return dp[i][j][k];
    
    int a=0;
    
    if(k==0)
    {
        a = max(arr[i]+sol(i+1,j,!k),arr[j]+sol(i,j-1,!k));
        
    }
    else
    {
         a = min(sol(i+1,j,!k)-arr[i],sol(i,j-1,!k)-arr[j]);
    }
    
   // deb(i,j,k,a);
    
    return dp[i][j][k]=a;
}

void solve()
{
   // cout << "-------------------" << "\n";
    
    cin>>n;
    
    arr = vi(n);
    
    for(int i=0;i<n;i++) cin>>arr[i];
    
    memset(dp,-1,sizeof(dp));
    
    cout<<sol(0,n-1,0)<<"\n";


  //  cout << "-------------------" << "\n";

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

    int t = 1;
   // cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int z = s - i - j;
      if (0 <= z && z <= k) {
        ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int CH_A = 0, CH_C = 1, CH_G = 2, CH_T = 3;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll dp[101][4][4][4] = {};
    ll MOD = 1000000007;
    rep (i, 4) { rep (j, 4) { rep (k, 4) {
        if (i == CH_A && j == CH_G && k == CH_C) dp[3][i][j][k] = 0;
        else if (i == CH_A && j == CH_C && k == CH_G) dp[3][i][j][k] = 0;
        else if (i == CH_G && j == CH_A && k == CH_C) dp[3][i][j][k] = 0;
        else dp[3][i][j][k] = 1;
    }}}
    rep (x, 4, n + 1) {
        rep (i, 4) { rep (j, 4) { rep (k, 4) {
            if (i == CH_A && j == CH_G && k == CH_C) dp[x][i][j][k] = 0;
            else if (i == CH_A && j == CH_C && k == CH_G) dp[x][i][j][k] = 0;
            else if (i == CH_G && j == CH_A && k == CH_C) dp[x][i][j][k] = 0;
            else { rep (p, 4) {
                if (!((p == CH_A && j == CH_G && k == CH_C) || (p == CH_A && i == CH_G && k == CH_C))) {
                    dp[x][i][j][k] += dp[x - 1][p][i][j];
                    dp[x][i][j][k] %= MOD;
                }
            }}
        }}}
    }
    ll ans = 0;
    rep (i, 4) { rep (j, 4) { rep (k, 4) {
        ans = (ans + dp[n][i][j][k]) % MOD;
    }}}
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	int n;
	cin>>n;
	for(int i=0; i*7<=n; i++){
		if((n-i*7)%4==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int h,w,x,y;
    while(1){
        cin >> h >> w;
        if (h==0&&w==0) break;
        for(x=0;x<h;x++){
            for(y=0;y<w;y++){
                cout << "#";
            }
            cout << endl;
        }
        cout <<endl;
    }
      
}


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

string map[12];

void dfs(int x, int y){
    map[y][x] = 0;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};

    for (int i = 0; i < 4; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];

        if (0 <= nx && nx < 12 && 0 <= ny && ny < 12 && map[ny][nx] == '1'){
            dfs(nx, ny);
        }
    }

}

int main(int argc, char const *argv[]){
    int ans;

    while(1){
        ans = 0;
        for (int i = 0; i < 12; i++){
            cin>>map[i];
        }

        if (cin.eof()) break;

        for (int i = 0; i < 12; i++){
            for (int j = 0; j < 12; j++){
                if (map[i][j] == '1'){
                    dfs(j, i);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3084
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let mut s = get!(String);
    while !s.is_empty() {
        let len = s.len();
        if s.ends_with("dream") {
            s = s[..len-5].to_string();
        } else if s.ends_with("dreamer") {
            s = s[..len-7].to_string();
        } else if s.ends_with("erase") {
            s = s[..len-5].to_string();
        } else if s.ends_with("eraser") {
            s = s[..len-6].to_string();
        } else {
            break;
        }
    }
    let r = if s.is_empty() {
        "YES"
    } else {
        "NO"
    };
    println!("{}", r);
}

Measured memory_bytes: 4352
n=int(input())
s=input()

def f(l,r):
    li=[]
    re=0
    for i in range(len(l)):
        if l[i] in r and l[i] not in li:
            re+=1
            li.append(l[i])
    return re
            
ans=0

for i in range(1,n):
    sl=s[:i]
    sr=s[i:]
    ans=max(ans,f(sl,sr))

print(ans)



Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		Scanner cin = new Scanner(System.in);

		int A = cin.nextInt();
		int list[] = new int[A];
		int tmp;
		for(int i=0;i<A;i++){
			list[i] = cin.nextInt();
		}

		Arrays.sort(list);
		tmp = list[0];
		int sum=0;
		for(int j=0;j<A;j++){
			if(tmp==list[j]){
			}else{
				sum+=list[j]-tmp;
				tmp = list[j];
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
	
	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens()) {
				String cad = br.readLine();
				if (cad == null)
					return null;
				tk=new StringTokenizer(cad);
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	public static void main(String args[]) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		String cad = sc.next();
		System.out.println(cad.substring(0, cad.length() - 8));
	}

}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int r;
	cin >> r;
	cout << r * r << '\n';
	return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int rem = a*b%2;
  if (rem == 1) {
  	cout << "Odd" << endl;
  }
  else {
  	cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
from collections import deque

class mf_graph:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
    
    def add_edge(self,v,w,cap):
        edge = [w,cap,None]
        edge[2] = rev_edge = [v,0,edge]
        self.graph[v].append(edge)
        self.graph[w].append(rev_edge)
    
    def bfs(self,s,t):
        self.level = [None]*self.N
        dq = deque([s])
        self.level[s] = 0
        while dq:
            v = dq.popleft()
            nlevel = self.level[v]+1
            for w,cap,_ in self.graph[v]:
                if cap and self.level[w] is None:
                    self.level[w] = nlevel
                    dq.append(w)
        return self.level[t] is not None
    
    def dfs(self,s,v,f):
        if v == s:
            return f
        for rev in self.it[v]:
            w,_,e = rev
            cap = e[1]
            if cap and self.level[w] is not None:
                if self.level[v] > self.level[w]:
                    d = self.dfs(s,w,min(f,cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
        return 0
    
    def flow(self,s,t,flow_limit=float('inf')):
        flow = 0
        while self.bfs(s,t):
            *self.it, = map(iter,self.graph)
            f = flow_limit
            while f:
                f = self.dfs(s,t,flow_limit-flow)
                flow += f
        return flow

    def min_cut(self,s):
        visited = [False]*self.N
        dq = deque([s])
        while dq:
            v = dq.pop()
            visited[v] = True
            for w,cap,_ in self.graph[v]:
                if cap and not visited[w]:
                    dq.append(w)


N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = mf_graph(N*M+2)

s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i+j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)

for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)
        if i+1 < N and S[i][j] == "." and S[i+1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)

print(dc.flow(s,t,10**9))
for u in range(N*M+2):
    for v,cap,_ in dc.graph[u]:
        ui,uj = divmod(u,M)
        vi,vj = divmod(v,M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"

for res in S:
    print("".join(res))


Measured memory_bytes: 85756
def main():
    n = int(input())
    aa = list(map(int, input().split()))

    pos = [0] * n
    neg = [0] * n

    pos[0] = aa[0]
    neg[0] = -aa[0]

    for i, a in enumerate(aa[1:-1], start=1):
        pos[i] = max(pos[i - 1] + a, neg[i - 1] - a)
        neg[i] = max(pos[i - 1] - a, neg[i - 1] + a)

    pos[n - 1] = pos[n - 2] + aa[n - 1]
    neg[n - 1] = neg[n - 2] - aa[n - 1]

    score = max(pos[n - 1], neg[n - 1])

    print(score)


main()

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

int main(){
  int n,m,x;
  cin >>n >>m >>x;
  int a[12][12];
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m){
      cin >>a[i][j];
    }
  }
  int ans = 100100100;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if(s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m){
      if(d[j]<x) ok = false;
    }
    if(ok && ans>cost) ans = cost;
  }
  if(ans==100100100) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin >> n;
  long long int sum=0,k=26;
  string s;
  int i=0;
  while(n>0)
  {
    if(n%k!=0)
    	s[i]=(char)(96+(n%k));
    else
      s[i]='z';
    if(n%26!=0)
      n=n/26;
    else
    {
      n=n/26;
      n--;}
    i++;
  }
  for(int j=i-1;j>=0;j--)
  {
    cout << s[j];
  }
}
  

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

#define int long long

int N, M, K;
vector<int> D;
vector<int> is_d;
vector<vector<int> > v;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M >> K;

  D = vector<int>(M);
  is_d = vector<int>(N, -1);  
  for ( int i = 0; i < M; i++ ) {
    cin >> D[i];    
    is_d[--D[i]] = i;    
  }

  v = vector<vector<int> >(N, vector<int>(K));
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < K; j++ ) {
      cin >> v[i][j];
      v[i][j]--;
    }
  }

  using Pii = pair<int, int>;
  queue<Pii> Q;
  Q.push(Pii((1<<M)-1, 0));
  vector<bool> used(1<<M, false);
  while ( !Q.empty() ) {
    Pii q = Q.front(); Q.pop();
    int b = q.first, c = q.second;

    if ( b == 0 ) {
      cout << c << endl;
      break;
    }

    if ( used[b] ) continue;
    used[b] = true;

    for ( int i = 0; i < K; i++ ) {
      int nb = 0;
      for ( int j = 0; j < M; j++ ) {
	if ( !((1<<j)&b) ) continue;
	int u = v[D[j]][i];
	if ( is_d[u] >= 0 ) nb |= (1<<is_d[u]);
      }
      Q.push(Pii(nb, c+1));      
    }
  }
  
  return 0;
}



Measured memory_bytes: 61836
#include <stdio.h>

struct tree
{
	int a, b, c;
};
struct tree x[10000];
int n;

void preParse(int u)
{
	if (u == -1)
		return;
	printf(" %d", u);
	preParse(x[u].b);
	preParse(x[u].c);
}

void inParse(int u)
{
	if (u == -1)
		return;
	inParse(x[u].b);
	printf(" %d", u);
	inParse(x[u].c);
}

void postParse(int u)
{
	if (u == -1)
		return;
	postParse(x[u].b);
	postParse(x[u].c);
	printf(" %d", u);
}

int main()
{
	int i, y, b, c, r;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		x[i].a = -1;

	for (i = 0; i < n; i++)
	{
		scanf("%d %d %d", &y, &b, &c);
		x[y].b = b;
		x[y].c = c;

		if (b != -1)
			x[b].a = y;
		if (c != -1)
			x[c].a = y;
	}

	for (i = 0; i < n; i++)
	{
		if (x[i].a == -1)
			r = i;
	}

	puts("Preorder");
	preParse(r);
	putchar('\n');
	puts("Inorder");
	inParse(r);
	putchar('\n');
	puts("Postorder");
	postParse(r);
	putchar('\n');

	return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t x){
	if(was_output)cout << " ";
	was_output = true;
	cout << x;
}

void outendl(){
	was_output = false;
	cout << endl;
}

class node{
	public:
		int key;
		node *left;
		node *right;
		node(int key):key(key), left(NULL), right(NULL){}
};

class tree{
	public:
		node *root;
		tree():root(NULL){}
};

void insert(tree &t, node *z){
	node *y = NULL;
	node *x = t.root;
	while(x!=NULL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}

	if(y==NULL){
		t.root = z;
	}else if(z->key < y->key){
		y->left = z;
	}else{
		y->right = z;
	}
}

void inorder(node *n){
	if(n==NULL)return;
	inorder(n->left);
	cout << " " << n->key;
	inorder(n->right);
}

void preorder(node *n){
	if(n==NULL)return;
	cout << " " << n->key;
	preorder(n->left);
	preorder(n->right);
}

bool find(node *n, int key){
	if(n==NULL)return false;
	if(key==n->key)return true;
	if(key < n->key)return find(n->left, key);
	return find(n->right, key);
}

int main(){
	tree t;
	int time;
	cin >> time;
	rep(i, time){
		string op;
		cin >> op;
		if(op=="insert"){
			int num;
			cin >> num;
			node *z = new node(num);
			insert(t, z);
		}else if(op=="print"){
			inorder(t.root);
			cout << endl;
			preorder(t.root);
			cout << endl;
		}else if(op=="find"){
			int num;
			cin >> num;
			cout << (find(t.root, num)?"yes":"no") << endl;
		}
	}


	return 0;
}




Measured memory_bytes: 15544
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, N); invar(int, M);
  vll A(N);
  multiset<int> p;
  rep(i, N) {
    cin >> A[i];
    p.emplace(A[i]);
  }
  
  rep(i, M) {
    auto curitr = p.rbegin();
    p.emplace(*curitr / 2);
    p.erase(next(curitr).base());
  }
  
  ll sum = 0;
  for(auto pp : p){
    sum += pp;
  }
  fin(sum);
}

Measured memory_bytes: 5760
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
using namespace std;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,(k-(n%k)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
const int inf = 0x3f3f3f3f;
const int MAXN = 5e5+1;
int A[MAXN], ans[MAXN];
int seg[1<<20], _M;
#define min(a,b) ((a)<(b)?(a):(b))
void update(int i, int v)
{
	seg[i+=_M] = v;
	for(i>>=1; i; i>>=1)
		seg[i] = min(seg[i<<1], seg[(i<<1)|1]);
}
int query(int l, int r)
{
	int res = inf;
	for(l+=_M-1, r+=_M+1; l^r^1; l>>=1, r>>=1)
	{
		if(~l&1) res = min(res, seg[l^1]);
		if(r&1) res = min(res, seg[r^1]);
	}
	return res;
}
void init(int N)
{
	for(_M=1; _M<=N+2; _M<<=1);
	memset(seg, inf, _M*2*sizeof(seg[0]));
}
int idx, K;
void solve(int x)
{
	while (1)
	{
		int pos = query(1, A[x]-1);
		if(pos >= x+K) break;
		solve(pos);
	}
	ans[x] = ++idx;
	update(A[x], inf);
}
int main()
{
	int N, i;
	scanf("%d%d", &N, &K);
	init(N);
	for(i=1; i<=N; ++i)
	{
		scanf("%d", A+i);
		update(A[i], i);
	}
	for(i=1; i<=N; ++i)
	{
		if(!ans[i]) solve(i);
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 27136
import java.util.*
 
fun main(args: Array<String>) {
  val (N, M) = readInts()
  val edges = Array(N + 1) { mutableListOf<Int>() }
  repeat(M) {
    val (A, B) = readInts()
    edges[A].add(B)
    edges[B].add(A)
  }
 
  val memo = Array(N + 1) { -1 }
  memo[1] = 1
 
  val queue = ArrayDeque<Int>()
  queue.add(1)
  while (true) {
    if (queue.isEmpty()) break
    val n = queue.first
    queue.removeFirst()
    val e = edges[n]
    e.forEach {
      if (memo[it] == -1) {
        memo[it] = n
        queue.addLast(it)
      }
    }
  }
 
  // println(if (memo.count { it == -1 } <= 1) "Yes" else "No")
  println("Yes")
  print(buildString {
    for (i in 2 until memo.size) {
      appendln(memo[i])
    }
  })
}
 
fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }

Measured memory_bytes: 76732
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9+5;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    
    for(auto &it:a)
    {
        cin >> it;
    }
    
    vector<bool> dp(k+1,false);
    
    for(int stones=0;stones<=k;++stones)
    {
        for(auto k:a)
        {
            if(k<=stones && dp[stones-k]==false)
            dp[stones]=true;
        }
    }
    cout << (dp[k]?"First":"Second") ;
    
    return 0;
    
}


Measured memory_bytes: 3628
/**
 * Created by hiramekun at 20:51 on 2019-12-22.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll a, b;
    cin >> a >> b;
    for (ll i = 1; i <= 3; ++i) {
        if (i != a && i != b) {
            cout << i << '\n';
            return;
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> keihin(N);
  map<string,string> kekka;
  for(int i = 0;i < N;i++){
    cin >> keihin.at(i);
  }
  int x = 0;
  for(int i = 0;i < N;i++){
    if(!(kekka.count(keihin.at(i)))){
      kekka[keihin.at(i)] = keihin.at(i);
    }
  }
  cout << kekka.size() << endl;
}


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

bool is_acgt(char);

int main()
{
	std::string s;
	std::cin >> s;
	s.push_back('_');
	int count{}, max{};
	for (auto& e: s)
	{
		if (is_acgt(e)) count++;
		else
		{
			max = std::max(max, count);
			count = 0;
		}
	}
	printf("%d\n", max);

	return 0;
}

bool is_acgt(char c)
{
	char acgt[]{"ACGT"};
	for (int i{}; i < 4; i++)
		if (c == acgt[i])
			return true;
	return false;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int N = 100;
int color[N]; // i's visit status
int M[N][N];
int d[N];  // minimum weight
int p[N]; // i's parent vertex in MST
int n;

#define WHITE 0
#define GRAY 1
#define BLACK 2

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;


void prim(){
  int u, minv;

  REP0(i,n){
    color[i] = WHITE;
    d[i] = INTINF;
    p[i] = -1;
  }

  d[0] = 0;

  while (1) {
    minv = INTINF;
    u = -1;
    REP0(i,n){
      if( minv > d[i] && color[i] != BLACK ){
        u = i;
        minv = d[i];  // MSTの隣接辺のうち最小重みを選ぶ
      }
    }
    if ( u==-1 ) break; // 最小重みがなく終了
    color[u] = BLACK; // uをMSTに追加
    REP0(v,n){ // 新たなMSTで, 隣接する頂点の重みと親を更新
      if ( color[v] != BLACK && M[u][v] != INTINF  && d[v] > M[u][v] ) {
        d[v] = M[u][v];
        p[v] = u;
        color[v] = GRAY;
      }
    }
  }

 int sum = 0;
 REP0(i,n){ // MST内で親を持つ頂点について
   if( p[i] != -1 ) sum += M[i][p[i]];
 }
 std::cout << sum << '\n';
}


void input(){
  std::cin >> n;
  int w;
  REP0(i,n) REP0(j,n) {
    std::cin >> w;
    M[i][j] = (w==-1) ? INTINF : w;
  }
}


int main(int argc, char const *argv[]) {
  input();
  prim();
  return 0;
}



Measured memory_bytes: 3228
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
    {
        swap(a, b);
    }
    for (int i = 0; i < b; i++)
    {
        cout << a;
    }
    cout << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#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)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    int sum = 0,tum = 0;
    REP(i,N){
        int a = in();
        sum += a;
        tum += a*a;
    }
    ll answer = INT32_MAX;
    REP(i,201){
        chmin(answer,tum - 2 * sum * (i - 100) + N * (i - 100) * (i - 100));
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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

int main()
{
  int N, L;
  cin >> N >> L;
  vector<ll> a(N);
  priority_queue<P, vector<P>> pq;
  REP(i, N) cin >> a[i];

  ll idx = -1;
  REP(i, N - 1) {
    if (a[i] + a[i + 1] >= L) {
      idx = i;
      break;
    }
  }

  if (idx == -1) {
    cout << "Impossible" << endl;
    return 0;
  }

  vector<ll> ans;
  for (int i = idx; i < N - 1; i++) ans.PB(i);
  for (int i = idx - 1; i >= 0; i--) ans.PB(i);
  reverse(ALL(ans));

  cout << "Possible" << endl;
  for (auto& e : ans) cout << (e + 1) << endl;

  return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
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; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(18);

	int D; cin >> D;
	vi c(26); vin(c);
	vvi s(D, vi(26));
	rep(i, D){
		rep(j, 26){
			cin >> s.at(i).at(j);
		}
	}
	vi t(D); vin(t);
	long long int satisfaction = 0;

	vi last_day(26, 0);
	rep(i, D){
		satisfaction += s.at(i).at(t.at(i) - 1);
		//cout << "t " << t.at(i) << " s " <<  s.at(i).at(t.at(i) - 1)<< " i " << (i + 1) << endl;
		last_day.at(t.at(i) - 1) = (i + 1);
		rep(j, 26){
			satisfaction -= c.at(j) * ((i+1) - last_day.at(j));
		}
		cout << satisfaction <<  endl;
	}
}

Measured memory_bytes: 3652
A, B = map(int, input().split())
def length(a):
    count=0
    while a>0:
        a=a//2
        count+=1
    return count

def make_sum(X):
    X_len=length(X)
    each = [0] * X_len
    for i in range(X_len):
        temp = (X+1) //2**(i + 1)*2**i + max((X+1) % 2 ** (i + 1) - 2 ** i, 0)
        each[i] = temp
    return each
#print(length(A), length(B))
#print(make_sum(A), make_sum(B))

A_lst=make_sum(A-1)
B_lst=make_sum(B)
A_lst+=[0]*(length(B)-length(A-1))
maxlen=length(B)
#print(maxlen)
answer=0
for i in range(maxlen):
    answer+= ((B_lst[i]-A_lst[i])%2)*2**i
#print('/n')
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

const int MAX_N = (2e+5)+10;
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
void makefact(ll n){//MODは素数かつnより大きい
    ll ans = 1;
    fact.at(0) = ans;
    fact_inv.at(0) = ans;
    reps(i,1,n+1){
        (ans *= i)%=MOD;
        fact.at(i) = ans;
        fact_inv.at(i) = fastpow(ans,MOD-2);
    }
    return;
}

int main() {
    ll X;
    cin>>N>>X;
    vec s(N);
    rep(i,N) cin>>s[i];
    sort(s.begin(),s.end());
    mat dp(N,vec(X+1,0)), sum(N,vec(X+1,0));//dp[i]に*(N - i - 1)!はあとで
    rep(i,N){
        rep(x,X+1){
            ll to = x % s[i];
            if(i == 0){
                dp[i][x] = sum[i][x] = to;
            }else{
                dp[i][x] = sum[i-1][to];
                (sum[i][x] = i*sum[i-1][x] + dp[i][x])%=MOD;
            }
            //if(x == X) cout<<i<<' '<<dp[i][x]<<' '<<sum[i][x]<<endl;
        }
    }
    ll ans = 0;
    makefact(N);
    rep(i,N){
        ll temp = dp[i][X];
        (temp *= fact[N-1])%=MOD;
        (temp *= fact_inv[i])%=MOD;
        (ans += temp)%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 317168
package main

import (
	"fmt"
	"sort"
)

func factorial(n int) int {
	if n == 1 {
		return 1
	}
	return factorial(n-1) * n
}

func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}

func permute(nums []int, ret *[]string) {
	*ret = append(*ret, fmt.Sprint(makeCopy(nums)))

	n := len(nums)
	p := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		p[i] = i
	}
	for i := 1; i < n; {
		p[i]--
		j := 0
		if i%2 == 1 {
			j = p[i]
		}

		nums[i], nums[j] = nums[j], nums[i]
		*ret = append(*ret, fmt.Sprint(makeCopy(nums)))
		for i = 1; p[i] == 0; i++ {
			p[i] = i
		}
	}
}

func permutation(nums []int) []string {
	n := factorial(len(nums))
	ret := make([]string, 0, n)
	permute(nums, &ret)
	return ret
}

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

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	q := make([]int, n)
	for i := range p {
		fmt.Scan(&p[i])
	}
	for i := range q {
		fmt.Scan(&q[i])
	}

	nums := make([]int, n)
	for i := 1; i <= n; i++ {
		nums[i-1] = i
	}

	pattern := permutation(nums)
	sort.Strings(pattern)

	var a, b int
	for i, v := range pattern {
		if v == fmt.Sprint(p) {
			a = i + 1
		}
		if v == fmt.Sprint(q) {
			b = i + 1
		}
	}
	fmt.Println(abs(a - b))
}


Measured memory_bytes: 4864
from collections import deque


def submit():
    s = input().strip()
    q = deque()
    ans = 0

    for c in s:
        if len(q) == 0:
            q.append(c)
        else:
            top = q.pop()
            if top != c:
                ans += 2
            else:
                q.append(top)
                q.append(c)
            
    print(ans)


if __name__ == "__main__":
    submit()

Measured memory_bytes: 4212
S = int(input())
#	X1 = X1 = 0
#	S = X2 * Y3 - X3 * Y2
#	X2 = 10^9, X3 = 1
#	S = 10^9 * Y3 - Y2
Y3 = (S + 10**9 - 1) // 10**9
Y2 = 10**9 * Y3 - S
print(0, 0, 10**9, Y2, 1, Y3)

Measured memory_bytes: 2940
X, Y = map(int, input().split())

flag1 = (Y - 2 * X >= 0) and ((Y - 2 * X) % 2 == 0)
flag2 = (4 * X - Y >= 0) and ((4 * X - Y) % 2 == 0)

print("Yes" if flag1 and flag2 else "No")


Measured memory_bytes: 61856
#include<bits/stdc++.h>
using namespace std;
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define MOD 1000000007
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
char F[200];

int nums[maxn];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    } 
    return ret*sgn;
}

inline void write( ll x ) {
    ll tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(F[--cnt]);
}

int main()
{
    NOS
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int n;
    cin >> n;
    int sum = 0;

    for(int i = 1; i <= n; i++)
    {
        cin >> nums[i];
        sum += nums[i];
    }

    int sum1 = sum / n;
    int sum2 = sum1 + 1;

    int ans1 = 0;
    int ans2 = 0;

    for(int i = 1; i <= n; i++)
    {
        ans1 += (sum1 - nums[i]) * (sum1 - nums[i]);
        ans2 += (sum2 - nums[i]) * (sum2 - nums[i]);
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i] != key)i++;
  return i != n;
}

int main(){
  int i,n,A[10000+1],q,key,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if( search(A,n,key) ) sum++;
  }
  printf("%d\n",sum);

  return 0;
}


	    



Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
#define lli long long
lli a[200005];
lli ct[200005];

int main() 
{
    int n;
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> a[i];
        ct[a[i]]++;
    }
    
    lli ans = 0;
    
    for(int i=1;i<=n;i++) ans+=((1LL*ct[i]*(ct[i]-1))/2);
    
    for(int i=0;i<n;i++) {
        lli temp = ans;
        temp -= ((1LL * (ct[a[i]] * (ct[a[i]]-1)))/2);
        temp += ((1LL * ((ct[a[i]]-2) * (ct[a[i]]-1)))/2);
        cout << temp << endl;
    }
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N, M;
string s[110], t[110];

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> s[i];
    cin >> M;
    rep(i, M) cin >> t[i];
    int ans = 0;
    rep(i, N) {
        string u = s[i];
        int ans_cand = 0;
        rep(j, N) if (s[j]==u) ans_cand++;
        rep(j, M) if (t[j]==u) ans_cand--;
        ans = max(ans, ans_cand);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n, count = 0;
	cin >> n;
	while (n > 0) {
		if (n % 10 == 9) {
			cout << "Yes" << endl;
			count++;
			break;
		}
		n /= 10;
	}
	if (count == 0)cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  int q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  int tmp=0,tmpv=0;
  n*=4;
  h=min(h,q*2);
  s=min(s,h*2);
  d=min(d,s*2);
  while(tmp+8<=n){
    tmpv+=d;
    tmp+=8;
  }
  while(tmp+4<=n){
    tmpv+=s;
    tmp+=4;
  }
  while(tmp+2<=n){
    tmpv+=h;
    tmp+=2;
  }
  while(tmp+1<=n){
    tmpv+=q;
    tmp+=1;
  }
  cout<<tmpv<<endl;
  return 0;
}

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


int selectionSort(int a[], int n) {
	int cnt = 0;

	for (int i = 0;i < n;i++) {
		int minj = i;

		for (int j = i;j < n;j++) {
			if (a[j] < a[minj]) minj = j;
		}

		if (i != minj) {
			swap(a[i], a[minj]);
			cnt++;
		}
	}

	return cnt;
}


int main()
{
	int n, t, a[100];
	cin >> n;

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

	t = selectionSort(a, n);

	for (int i = 0;i < n;i++) {
		cout << a[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}

	cout << t << endl;
    return 0;
}



Measured memory_bytes: 3080
# AOJ 0289: Infinite Express
# Python3 2018.6.23 bal4u

def calc(s, d):
	if s == d: return 0;
	ans = 0
	if s % 2 != 0:
		ans += 1
		s += 1
	if d % 2 != 0:
		ans += 1
		d -= 1
	return ans + calc(s>>1, d>>1);

n = int(input())
for i in range(n):
	s, d = map(int, input().split())
	print(calc(s, d))


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int n,m;
  ll a[100000];
  cin>>n>>m;
  rep(i,0,n) cin>>a[i];

  priority_queue<ll> que;
  rep(i,0,n) que.push(a[i]);

  rep(i,0,m){
    int cnt=que.top();
    que.pop();
    cnt/=2;
    que.push(cnt);
  }

  ll ans=0;
  rep(i,0,n){
    ans+=que.top();
    que.pop();
  }

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

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

int main(){
	int n;
	cin >> n;
	while(n){
		int p[100];
		for(int i = 0; i < n; i++){
			cin >> p[i];
		}
		sort(p,p+n);
		int a = 0;
		for(int i = 1; i < n-1; i++){
			a += p[i];
		}
		cout << a/(n-2) << endl;
		cin >> n;
	}
}

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

using namespace std;
typedef long long ll;

const int N=1e5+100;
int a[N];

int main()
{
   int n,k,q;
   scanf("%d%d%d",&n,&k,&q);
   int x;
   ll sum=0;
   for(int i=1;i<=q;i++){
    scanf("%d",&x);
    a[x]++;
   }
   for(int i=1;i<=n;i++){
      sum+=a[i];
   }
  // cout<<s
   for(int i=1;i<=n;i++){
     if(sum-a[i]<k) printf("Yes\n");
     else printf("No\n");
   }
    return 0;
}


Measured memory_bytes: 1024
import Data.Bits

main = do
    [a,b] <- map read. words <$> getLine :: IO [Int]
    print $ (f (a-1) `xor` f b)

f n | n <= 0 = 0
    | odd n = if odd (n `div` 2) then 0 else 1
    | otherwise = n `xor` f (n-1)

Measured memory_bytes: 3896