akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 10000
#define INFTY (1<<30)
#define rep(i,n)	for(int i=0;i<n;i++)
enum{
	white,
	gray,
	black,
};

int n;
vector<pair<int,int> >	adj[MAX];

void dijkstra(){
	priority_queue<pair<int,int> >	pq;
	int color[MAX];
	int d[MAX];
	rep(i,n){
		d[i]=INFTY;
		color[i]=white;
	}
	d[0]=0;
	pq.push(make_pair(0,0));
	color[0]=gray;
	while(!pq.empty()){
		pair<int,int> f=pq.top();	pq.pop();
		int u=f.second;
		color[u]=black;
		if(d[u]<f.first*(-1))	continue;
		rep(j,(int)adj[u].size()){
			int v=adj[u][j].first;
			if(color[v]==black)	continue;
			if(d[v]>d[u]+adj[u][j].second){
				d[v]=d[u]+adj[u][j].second;
				pq.push(make_pair(d[v]*(-1),v));
				color[v]=gray;
			}
		}
	}
	rep(i,n){
		cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
	}
}

int main(){
	int k,u,v,c;
	cin>>n;
	rep(i,n){
		cin>>u>>k;
		rep(j,k){
			cin>>v>>c;
			adj[u].push_back(make_pair(v,c));
		}
	}
	dijkstra();
	return 0;
}

Measured memory_bytes: 6308
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])
        cout<< "Yes\n";
    else
        cout<< "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  int l,r,a,b;
  cin >> l >> r;
  if(((r/2019)-(l/2019))>=1){
    cout << 0;
    return 0;
  }
  l = l%2019;
  r = r%2019;
  int ans = 2020;
  a = min(l,r);
  b = max(l,r);
  for(int i=a;i<=b;i++){
    for(int j=a;j<i;j++){
      ans = min((i*j)%2019,ans);
       
    }
  }
  cout << ans;
  
 
 return 0;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

if K <= 9:
    print(str(K))
else:
    tmp = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    k = 9
    while k < K:
        cur = tmp.popleft()
        ones_place = int(str(cur)[-1])
        if ones_place == 0:
            tmp.append(int(str(cur)+str(0)))
            tmp.append(int(str(cur)+str(1)))
            k += 2
        elif ones_place == 9:
            tmp.append(int(str(cur)+str(8)))
            tmp.append(int(str(cur)+str(9)))
            k += 2
        else:
            tmp.append(int(str(cur)+str(ones_place - 1)))
            tmp.append(int(str(cur)+str(ones_place)))
            tmp.append(int(str(cur)+str(ones_place+1)))
            k += 3

    print(str(tmp[-(k-K)-1]))

Measured memory_bytes: 5964
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        scanner.close();
        int resultA = x/500 * 1000;
        int resultB = (x%500)/5 * 5;
        int result = resultA + resultB;
        System.out.println(result);
        
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

class Main{
      public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	ArrayList<Integer> p = new ArrayList<>();
	for(int i=0;i<n;i++){
	    p.add(sc.nextInt());
	}
	Collections.sort(p);
	int a = 0;
	for(int i=0;i<k;i++){
	    a+=p.get(i);
	}
	System.out.println(a);
	sc.close();
      }
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,bottom,ceiling) for(auto (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(auto (i) = (ceiling); (i) >= (bottom); --(i))
#define repV(i,v) for(auto (i) = begin(v); (i) < end(v); ++(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1)/(d) + 1)
#define parity(a,b) ((a)^(b) & 1LL ^ 1LL)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = -1 + (1 << 30);
const ll INF_64 = -1 + (1LL << 62);
const int MOD = (int)1e9 + 7;

ull next_subset(ull subset){
	ull tem = subset + (subset & -subset);
	ull btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}

int n,x[200001];
ll ans = 0;

void solve(){
	
	int j,i = n - 1;
	
	while(i >= 0){
		ans += x[i];
		if(x[i] > i){
			cout<<-1<<endl;
			return;
		}
		j = i - 1;
		while(j >= 0 && x[j] == x[j + 1] - 1) --j;
		if(x[j] - j < x[i] - i){
			cout<<-1<<endl;
			return;
		}
		i = j;
	}
	
	cout<<ans<<endl;
	
	return;
}

void input(){
	
	cin>>n;
	rep(i,n) cin>>x[i];
	
	return;
}

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





Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, A;
    cin >> N >> A;
    cout << N*N - A << "\n";
    return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
/*
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};
*/
ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N, M, S;
llvec U, V, A, B;
llvec C, D;
ll Amax;
ll Cmax;
ll Nn;//number of nodes;

vector<vector<edge>> e;

ll state(ll x, ll c){
  return x*(Cmax+1) + c;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M >> S;
  U = llvec(M);
  V = llvec(M);
  A = llvec(M);
  B = llvec(M);
  
  C = llvec(N);
  D = llvec(N);
  
  Amax=0;
  rep(i, M){
    cin >> U[i] >> V[i] >> A[i] >> B[i];
    Amax = max(Amax, A[i]);
  }
  rep(i, N){
    cin >> C[i] >> D[i];
  }

  Cmax = (Amax)*(N-1);
  S = min(S, Cmax);
  Nn = (Cmax+1) * N;
  e = vector<vector<edge>>(Nn);
  //cerr << Nn << " " << Cmax << " " << Amax << endl;
  rep(i, M){
    FOR(j, A[i], Cmax+1){
      e[state(U[i]-1, j)].push_back({state(V[i]-1, j-A[i]), B[i]});
      e[state(V[i]-1, j)].push_back({state(U[i]-1, j-A[i]), B[i]});
    }
  }
  
  rep(i, N){
    rep(j, Cmax){
      e[state(i, j)].push_back({state(i, min(j+C[i], Cmax)), D[i]});
    }
  }
  
  
  llvec d(Nn, 1e18);
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, state(0, S)});
  d[state(0, S)]=0;
  while(!que.empty()){
    P n = que.top();
    que.pop();
    if(d[n.second]<n.first)continue;
    for(auto i: e[n.second]){
      ll a = i.x;
      if(d[a]<=d[n.second]+i.c){
        continue;
      }else{
        d[a]=d[n.second]+i.c;
        que.push({d[a], a});
      }
    }
  }
  
  FOR(i, 1, N){
    ll ans = 1e18;
    rep(c, Cmax+1){
      ans = min(d[state(i, c)], ans);
    }
    cout << ans << endl;
  }
    return 0;
}


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

int main() {
	long long n, p, m = 1, q = 2;

	cin >> n >> p;

	while(q <= sqrt(p)){
		int i = 0;
		while(p % q == 0){
			p /= q;
			i++;
		}
		for(int j = 0;  j < (i / n); j++)
			m *= q;
		q++;
	}

	if(n == 1)
		m *= p;

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	char S[100001];
	while(~scanf("%s", S)) {
		string T = S;
		reverse(T.begin(), T.end());
		for(char &c : T) {
			if(c == 'b')c = 'd';
			else if(c == 'd')c = 'b';
			else if(c == 'p')c = 'q';
			else if(c == 'q')c = 'p';
		}
		bool ans = T == S;
		puts(ans ? "Yes" : "No");
	}
	return 0;
}


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

int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i,S.size()){
        if(S[i] == T[i]) ans++;
    }
    ans = S.size() - ans;
    cout << ans << endl;
}

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

int main(){
	char num[3];
	cin >> num;
	for(int i = 0; i < 3; i++){
		if(num[i] == '1')
			num[i] = '9';
		else if(num[i] == '9')
			num[i] ='1';
	}
	cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<ctime>  
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
#define pb push_back


typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<long long> vll;

const int MAXN = 1e6 + 10;

int n;
ll a[MAXN] = {0, 3,2,1};

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n;
    ll tot = 0, cur = 0;
    rep(i, 0, n) {
    	cin >> a[i];
    	tot += a[i];
    }
    ll res = 1e18;
    rep(i, 0, n - 1) {
    	cur += a[i];
    	res = min(res, abs(cur * 2 - tot));
    }
    cout << res << endl;


    return 0;
}













Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let ci: Vec<char> = s.chars().collect();
    let n = s.len();

    let mut ans = "Yes";
    let w = (n + 1) / 2;

    for i in 0..((n-1)/2) {
        // println!("{} {} {} {}", i, i+w, ci[i], ci[i+w]);
        if ci[i] != ci[i+w] {
            ans = "No";
            break;
        }
    }

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


Measured memory_bytes: 4352
import heapq
 
N,M = map(int,input().split())
Price_List = list(map(lambda x:x*(-1),map(int,input().split())))
heapq.heapify(Price_List)
for i in range(M):
    val = heapq.heappop(Price_List)* -1 // 2 * -1
    heapq.heappush(Price_List,val)
print(-sum(Price_List))


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

using namespace std;

int main() {
 int n;
 cin >> n;
 vector <int> a(n + 1);
 for (int i = 0; i < n; i++) {
    cin >> a[i];
 }

 vector <int> ans(n + 1);
 for (int i = 0; i < 32; i++) {
    int h = 0, nh = 0;
    for (int j = 0; j < n; j++) {
        if ((1 << i) & a[j]) {
            h++;
        }
        else {
            nh++;
        }
    }
    if (h % 2 == 0) {
        for (int j = 0; j < n; j++) {
            if ((1 << i) & a[j]) {
                ans[j] += (1 << i);
            }
        }
    }
    else {
        for (int j = 0; j < n; j++) {
            if (!((1 << i) & a[j])) {
                ans[j] += (1 << i);
            }
        }
    }
 }
 for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
 }
 return 0;
}


Measured memory_bytes: 4716
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    int n;
    int h[110];
    cin>>n;
    int cnt=1;
    bool flag;
    REP(i,n) cin>>h[i];
    for(int i=1;i<n;i++){
        flag=true;
        for(int j=0;j<i;j++){
            if(h[i]<h[j]) flag=false;
        }
        
        if(flag) cnt++;
    }
    
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
strs = list(reversed(S))
rev_S = ''.join(strs)
while True:
  if rev_S[:6] == 'resare':
    rev_S = rev_S[6:]
    continue
  elif rev_S[:7] == 'remaerd':
    rev_S = rev_S[7:]
    continue
  elif rev_S[:5] == 'esare' or rev_S[:5] == 'maerd':
    rev_S = rev_S[5:]
    continue
  else:
    break

if rev_S == '':
  print('YES')
else:
  print('NO')



Measured memory_bytes: 82552
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
typedef long long int ll;
typedef double ld;
using namespace std;

class afd {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a,b;
	    in>>a>>b;

	    int p = 500*a;
	    if(p>=b)
	        out<<"Yes"<<endl;
        else
            out<<"No"<<endl;

	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
	afd solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef long long ll;
ll arr[100005] ;
ll MOD = 1e9 + 7;

int main()
{
  ll n, cnt = 0 ;
  cin >> n ;
  for(int i = 1; i < n; i++){
    if( (n - i) == i or (n - i) < i )  break ;
    else  cnt++ ;
  }

  cout << cnt << endl ;
}


Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))
S=(sum(X))/N
e=S-int(S)
if e<=0.5:
  p=int(S)
  t=0
  for i in range(N):
    t=t+(X[i]-p)**2
  print(t)
else:
  p=int(S)+1
  t=0
  for i in range(N):
    t=t+(X[i]-p)**2
  print(t)

Measured memory_bytes: 38384
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a + b >= c){
            System.out.println(c + b);
        }else{
            System.out.println(a + b + b + 1);
        }




    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25684
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return tuple(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n = readint()
p = readints()
q = readints()

from itertools import permutations

a = 0
b = 0

for i,x in enumerate(permutations(range(1,n+1),n)):
    if x == p:
        a = i
    if x == q:
        b = i
print(abs(a-b))

Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a;
    cin >> a;
    int ans = a*a*3;
    cout << ans << endl;
}

Measured memory_bytes: 256
pub mod contest {
    pub mod input {
        use std::io;
        use std::str::FromStr;
        use std::fmt::Debug;

        pub fn read_line<F>() -> F
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input.trim().parse().unwrap()
        }

        pub fn read_words<F>() -> Vec<F>
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input
                .split_whitespace()
                .map(|i| i.parse().unwrap())
                .collect()
        }

        pub fn read_matrix<F>(num_lines: usize) -> Vec<Vec<F>>
        where F: FromStr, <F as FromStr>::Err: Debug {
            (0..num_lines).map(|_| read_words()).collect()
        }

        // 所有権的な問題で SplitWhitespace を直接持てないので妥協
        // まあ、一行のデータの数なんてそんなに多くないだろうし
        pub struct WordsReader {
            words: Vec<String>,
            cur: usize,
        }

        impl WordsReader {
            pub fn new() -> Self {
                let mut input = String::new();
                io::stdin().read_line(&mut input).unwrap();
                WordsReader {
                    words: input.split_whitespace().map(|i| i.to_owned()).collect(),
                    cur: 0,
                }
            }

            pub fn next<F>(&mut self) -> F
            where F: FromStr, <F as FromStr>::Err: Debug {
                let v: F = self.words[self.cur].parse().unwrap();
                self.cur += 1;
                v
            }
        }
    }
}


use std::collections::HashSet;

fn step(x: u64, k: u64) -> u64 {
    if x < k {
        k - x
    } else {
        x % k
    }
}

fn create_set(n: u64, k: u64) -> HashSet<u64> {
    let mut x = n;
    let mut all = HashSet::new();
    loop {
        if all.contains(&x) {
            break
        }
        all.insert(x);
        x = step(x, k);
    }
    all
}

fn solve(n: u64, k: u64) -> u64 {
    let set = create_set(n, k);
    *set.iter().min().unwrap()
}

#[test]
fn test_solve() {
    assert_eq!(solve(7, 4), 1);
    assert_eq!(solve(2, 6), 2);
    assert_eq!(solve(1000000000000000000, 1), 0);
}

fn main() {
    let mut wr = contest::input::WordsReader::new();
    let n: u64 = wr.next();
    let k: u64 = wr.next();
    println!("{}", solve(n, k));
}


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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    int amari = n % 10;
    if (amari == 2 || amari == 4 || amari == 5 || amari == 7 || amari == 9) {
        cout << "hon" << endl;
    } else if (amari == 3) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	vector<int> perm(n);
	iota(perm.begin(), perm.end(), 0);
	long long ans = 0;
	do {
		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			bool found = false;
			for (int &nbr : g[perm[i]]) {
				if (nbr == perm[i + 1]) found = true;
			}
			ok &= found;
		}
		ans += ok;
	} while (next_permutation(perm.begin() + 1, perm.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int main(){
	int a,b;
	cin>>a;
	cin>>b;
	if(a%2==1&&b%2==1)cout<<"Yes";
	else cout<<"No";
	return 0;

}

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

template<typename T> 
map<T,int> factorize(T x){
    map<T,int> mp;
    for (T i = 2; i*i <= x; i++){
        while (x%i == 0) {
            x /= i;
            mp[i]++;
        }
        if (x == 1) break;
    }
    if (x != 1) mp[x]++;
    return mp;
}

int main(void){
    ll n, p;
    cin >> n >> p;
    auto cnt = factorize(p);
    ll res = 1;
    for (auto itr : cnt) {
        if (itr.second >= n) {
            res *= pow(itr.first, (itr.second / n));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
w = input()
t = ""
while True:
  line = input()
  if line == "END_OF_TEXT":
    break
  else:
    t += " " + line.lower()

words = t.split()
counter = 0
for i in range(len(words)):
  if words[i] == w:
    counter += 1

print(counter)


Measured memory_bytes: 5556
n = int(input())
red = []
for i in range(n):
    a, b = map(int, input().split())
    red.append((a, b))

blue = []
for i in range(n):
    c, d = map(int, input().split())
    blue.append((c, d))

red = sorted(red, key=lambda x: x[1])
blue.sort()

count = 0
while len(blue) >= 1:
    c, d = blue.pop(0)
    tmp = []
    r = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            r.append((a, b))
        else:
            tmp.append((a, b))
    if len(r) >= 1:
        count += 1
        r = sorted(r, key=lambda x:x[1])
        r.pop()
        tmp.extend(r)
    red.extend(tmp)
print(count)


Measured memory_bytes: 3444
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
LL max(LL a, LL b){
  if (a > b) {
    return a;
  }else return b;
}

int main(void)
{
  int n;
  scanf("%d", &n);
  n %= 10;
  if (n==2 || n==4|| n==5|n==7|n==9) {
    printf("hon\n" );
  }else if(n==3){
    printf("bon\n");
  }else{
    printf("pon\n" );
  }
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;


bool check(vector<int>& seq, int target){
    unordered_set<int> viewed[2];
    int cur = 0;
    viewed[cur].insert(0);
    for(int i=0;i<seq.size();i++){
        int next = cur ^ 1;
        viewed[next].clear();
        for(int v : viewed[cur]){
            viewed[next].insert(v + seq[i]);
            viewed[next].insert(v - seq[i]);
        }
        cur = next;
    }
    return (viewed[cur].count(target) > 0);
}

int main(){
    string s;
    cin >> s;
    int tx, ty;
    cin >> tx >> ty;

    vector<int> fcnt[2];
    int dir = 0;

    if(s[0] == 'F'){
        tx--;
    }else{
        dir++;
    }

    for(int i=1;i<s.size();i++){
        if(s[i] == 'F'){
            int cnt = 0;
            while(i < s.size() && s[i] != 'T'){
                i++;
                cnt++;
            }
            fcnt[dir].push_back(cnt);
        }
        dir ^= 1;
        assert(i >= s.size() || s[i] == 'T');
    }

    if(check(fcnt[0], tx) && check(fcnt[1], ty)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
int H, W, N;
set<pair<int, int>> F, cand;
ll ans[10];

void add_cand(int y, int x) {
   if (y >= 0 && y < H-2 && x >= 0 && x < W-2) cand.insert({y, x});
}

int main() {
   cin >> H >> W >> N;
   rep (i, N) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      F.insert({a, b});
      for (int dy = 0; dy <= 2; dy++) {
         for (int dx = 0; dx <= 2; dx++) {
            add_cand(a-dy, b-dx);
         }
      }
   }

   ans[0] = (ll)(H-2) * (W-2);
   for (auto aa : cand) {
      int y = aa.first, x = aa.second;
      int num = 0;
      for (int i = 0; i < 3; i++) {
         for (int j = 0; j < 3; j++) {
            if (F.count({y+i, x+j})) ++num;
         }
      }
      ans[0]--;
      ans[num]++;
   }

   for (int i = 0; i <= 9; i++) {
      printf("%lld\n", ans[i]);
   }

   return 0;
}

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

int p[100001][17],a[100001];
int A,B;

bool check(int x){
	int tmp=B,stp=0;
	while(x){
		if(x&1)	tmp=p[tmp][stp];
		stp++;
		x>>=1;
	}
	return tmp<=A;

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,L,k;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int tmp=n;
	cin>>L>>k;
	for(int i=n;i>=1;i--){
		while(tmp>0&&a[i]-a[tmp]<=L)
			tmp--;
		p[i][0]=tmp+1;
	}
	for(int j=1;j<=16;j++)
		for(int i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	for(int i=1;i<=k;i++){
		cin>>A>>B;
		if(A>B)	swap(A,B);
		int l=0,r=100000;
		while(l<r){
			int mid=(l+r)/2;
			if(check(mid))
				r=mid;
			else
				l=mid+1;
		}
		cout<<l<<'\n';
	}
}


Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///


int main(){

    int n;
    I(n);
    int cnt = 0;
    map<int,int>mp;
    mp[n]++;cnt++;
    while(n){
        cnt++;
        if(n% 2== 0){
            n/=2;
        }
        else n= 3* n + 1;

        if(mp[n] != 0){
            cout<<cnt<<endl;
            break;
        }
        mp[n]++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

int N;
VI p, x;
VVI child;

vector<P> dist;
int dfs(int v) {
  if (dist[v].first != -1) {
    return dist[v].first;
  }
  if (v == 0) {
    return dist[v].first = 0;
  }
  return dist[v].first = (dfs(p[v]) + 1);
}

void solve() {
  dist = vector<P>(N, {-1, 0});
  REP (i, N) {
    dist[i].second = i;
  }
  REP (i, N) {
    dfs(i);
  }
  sort(dist.begin(), dist.end(), greater<P>());

  VI y(N, 0);
  REP (i, N) {
    int v = dist[i].second;
    VVI dp(child[v].size()+1, VI(x[v]+1, 0));
    dp[0][0] = 1;
    REP (j, child[v].size()) {
      REP (k, x[v]+1) {
        if (k - x[child[v][j]] >= 0 && dp[j][k - x[child[v][j]]]) {
          dp[j+1][k] = 1;
        }
        if (k - y[child[v][j]] >= 0 && dp[j][k - y[child[v][j]]]) {
          dp[j+1][k] = 1;
        }
      }
    }
    /* cout << "v = " << v << endl; */
    /* REP (j, child[v].size()+1) { */
    /*   REP (k, x[v]+1) { */
    /*     cout << dp[j][k] << ' '; */
    /*   } */
    /*   cout << endl; */
    /* } */
    int change = -1;
    for (int k = x[v]; k >= 0; k--) {
      if (dp[child[v].size()][k]) {
        change = k;
        break;
      }
    }
    if (change == -1) {
      cout << "IMPOSSIBLE" << endl; return;
    }
    int sum = 0;
    REP (j, child[v].size()) {
      sum += x[child[v][j]];
      sum += y[child[v][j]];
    }
    y[v] = sum - change;
    /* cout << "y = " << y[v] << endl; */
  }
  cout << "POSSIBLE" << endl;
}

signed main() {
  cin >> N;
  p = VI(N); x = VI(N);
  child = VVI(N);
  REP (i, N-1) {
    cin >> p[i+1]; p[i+1]--;
    child[p[i+1]].push_back(i+1);
  }
  REP (i, N) {
    cin >> x[i];
  }

  solve();
}


Measured memory_bytes: 2412
#include<stdio.h>
#define MAX 2000
int A[MAX], M[MAX];
int a,b,i,j,k,f=0;
 
int solve(int p, int t){
    if (t - A[p] == 0){
        return 1;
    }
    if (p+1>a){
        return 0;
    }
    if (solve(p + 1, t - A[p]) || solve(p + 1, t) ){
        return 1;
    }
    return 0;
}
 
 
int main(){
     
 
    scanf("%d",&a);
    for (i = 0; i < a;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&b);
 
    for (i = 0; i < b;i++){
        scanf("%d",&M[i]);
    }
 
    for (i = 0; i < b; i++){
        if (solve(0, M[i])){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
 
    return 0;
 
}

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

int main(){
  int n=0,n1,n2;
  char s1,s2,s;
  while(cin>>s1>>s>>s2){
    n1=s1-'A';
    n2=s2-'A';
    if(n1==n)n=n2;
    else if(n2==n)n=n1;
  }
    if(n==1)cout<<'B'<<endl;
    else if(n==0)cout<<'A'<<endl;
    else if(n==2)cout<<'C'<<endl;
  return 0;
}

Measured memory_bytes: 3108
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

map<ll, list<ll>> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll d, res=0, x, y, m;
        cin >> d;
        ll c[26], ans[d];
        ll arr[d][26];
        ll la[26];
        for(ll i=0; i<26; i++) {
            cin >> c[i];
            la[i]=-1;
        }
        for(ll i=0; i<d; i++) {
            for(ll j=0; j<26; j++) {
                cin >> arr[i][j];
            }
        }
        for(ll i=0; i<d; i++) {
            cin >> ans[i];
            ans[i]--;
        }
        cin >> m;
        for(ll q=0; q<m; q++) {
            cin >> x >> y;
            x--, y--;
            ans[x]=y;
            res=0;
            for(ll i=0; i<26; i++) {
                la[i]=-1;
            }
            for(ll i=0; i<d; i++) {
                la[ans[i]]=i;
                res+=arr[i][ans[i]];
                for(ll j=0; j<26; j++) {
                    res-=((c[j])*(i-la[j]));
                }
            }
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 3260
#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
	double x1,y1,x2,y2,dis;
	cin>>x1>>y1>>x2>>y2;
	dis = sqrt(pow((x1 - x2),2) + pow((y1 - y2),2));
	cout<<setprecision(9)<<fixed<<dis<<endl;
	return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

ll n,k;

ll query(ll a,ll b,ll c){
	if (b%a==0) return 2ll*b;
	ll t=b/a;
	return 2ll*t*a+a+(b-t*a)+query(b-a*t,a-(b-a*t),a);
}

int main(){
	scanf("%lld%lld",&n,&k);
	printf("%lld\n",k+query(n-k,k,n));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string x;
    cin>>x;
    int n=x.size();

    int s=0,cnt=0;
    rep(i,n){
        if(x[i]=='S') s++;
        else{
            if(s>0){
                cnt++;
                s--;
            }
        }
    }

    cout<<n-2*cnt<<endl;
} 


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;

    int a[N-1],b[N-1];
    Graph G(N);
    rep(i,N-1){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    int c[N];
    int cou=0;
    int x=0;
    rep(i,N){
        cin>>c[i];
        if(cou<G[i].size()){
            cou=G[i].size();
            x=i;
        }
        
    }
    sort(c,c+N);
    reverse(c,c+N);

    int ans=0;
    vector<int> dist(N, -1);
    queue<int> que;
    dist[x] = c[0];
    que.push(x);
    int coun=1;
    while (!que.empty()) {
        int v = que.front(); 
        que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] == -1) {
                dist[nv] = c[coun];
                coun++;
                ans+=min(dist[nv],dist[v]);
                que.push(nv);
            }
        }
    }
    cout << ans << endl;
    rep(i,N){
        cout << dist[i] << " ";
    }
    cout << endl;








    



}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn],n,m;
bool check(int mid)
{
	int mi=1e9,j=-1;
	for(int i=m-1;i>=1;i--)
	{
		int a1=a[i]>=mid,a2=a[i+1]>=mid;
		if(a1==a2)
		{
			mi=m-i-1;
			j=a1;
			break;
		}
	}
	for(int i=m;i<n;i++)
	{
		int a1=a[i]>=mid,a2=a[i+1]>=mid;
		if(a1==a2)
		{
			if(mi>i-m)
			{
				mi=i-m;
				j=a1;
			}
			break;
		}
	}
	if(j==-1)return a[1]>=mid;
	else return j;
}
int main()
{
//	freopen("night.in","r",stdin);
//	freopen("night.out","w",stdout);
	int l=2e9,r=0;
	scanf("%d",&m);
	n=m*2-1;
	for(int i=1;i<=n;i++)
		scanf("%d",a+i),l=min(l,a[i]),r=max(a[i],r);
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",l-1);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = ([int(x) for x in input().split()])
B = ([int(x) for x in input().split()])
C = ([int(x) for x in input().split()])

Sat = 0
j = 0
for i in A:
    Sat += B[i-1]
    if (i - j == 1) & (j != 0):
        Sat += C[j-1]
    j = i

print(Sat)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

struct node {
	int low, high;
	int mx;
	node *l, *r;

	node(int _low, int _high, int A[] = NULL): low(_low), high(_high), mx(0), l(NULL), r(NULL) {

		if (A == NULL)
			return;

		if (low == high) {
			mx = A[low];
		}
		else {


			l = new node(low, (low + high) / 2, A), r = new node((low + high + 2) / 2, high, A);

			combine();

		}

	}

	void combine() {

		if (l == NULL) {
			return;
		}

		mx = max(l->mx, r->mx);

	}

	void point_update(int pos, int val) {
		if (low == high) {

			mx = val;
		}

		else {

			int mid = (low + high) / 2;

			if (pos <= mid) {
				l->point_update(pos, val);

			}
			else {
				r->point_update(pos, val);
			}


			combine();
		}

	}

	int range_max(int lt, int rt) {

		if (lt == low && rt == high) {
			return mx;
		}
		if (l == NULL) {
			return mx;
		}

		int mid = (low + high) / 2;

		if (rt <= mid) {
			return l->range_max(lt, rt);
		}

		if (lt > mid)return r->range_max(lt, rt);

		return max(l->range_max(lt, mid), r->range_max(mid + 1, rt));


	}


	~node() {
		if (l != NULL)delete(l);

		if (r != NULL)delete(r);
	}


};




int n, k;

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

	cin >> n >> k;

	vector<int>a(n);

	int grosso = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		grosso = max(grosso, a[i]);
	}

	grosso += k;

	int dp[grosso + 1];

	memset(dp, 0, sizeof(dp));


	node tree(0, grosso, dp);


	for (int i = 0; i < n; i++) {
		int meglio = 0;
		int left = max(0, a[i] - k);
		int right = min(a[i] + k, grosso);

		meglio = max(meglio, tree.range_max(left, a[i]));

		meglio = max(meglio, tree.range_max(a[i], right));



		dp[a[i]] = max(dp[a[i]], meglio + 1);

		tree.point_update(a[i], dp[a[i]]);

		debug() << imie(meglio) imie(a[i]) imie(dp[a[i]]);


	}

	int ans = 0;
	for (int i = 0; i <= grosso; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;



}


Measured memory_bytes: 62668
N=int(input())
xy=[tuple(map(int,input().split())) for _ in range(N)]
ans=0
zmi=10**10
zma=-10**10
wmi=10**10
wma=-10**10
for x,y in xy:
    zmi=min(zmi,x+y)
    zma=max(zma,x+y)
    wmi=min(wmi,x-y)
    wma=max(wma,x-y)
print(max(zma-zmi,wma-wmi))

Measured memory_bytes: 35964