akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int a[110];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	int ans=0;
	for(int i=0;i<n;i++){
		int idx=i;
		for(int j=i+1;j<n;j++)if(a[j]<a[idx])idx=j;
		if(i!=idx){
			int t=a[i];
			a[i]=a[idx];
			a[idx]=t;
			ans++;
		}
	}
	for(int i=0;i<n;i++)printf("%d%c",a[i],i==n-1?10:32);
	printf("%d\n",ans);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int digitSum(int N)
{
  int ret = 0;
  while (N > 0)
  {
    ret += N % 10;
    N /= 10;
  }
  return ret;
}

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

  int ans = inf;
  for (int i = 1; i < N; i++)
  {
    int A = i;
    int B = N - A;
    chmin(ans, digitSum(A) + digitSum(B));
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

// Delete the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003, M_MAX = 200003;
int h[N_MAX], cntEdge;
struct Edge {
  int tar, nxt;
  Edge() {}
  Edge(int tar, int nxt) : tar(tar), nxt(nxt) {}
}ed[M_MAX];

int col[N_MAX], cntNode, tub[3];
int dfs(int x) {
  ++cntNode, ++tub[col[x]];
  bool ext[2] = {0, 0};
  int state = 0;
  for (int i = h[x]; i; i = ed[i].nxt) {
    ++cntEdge, ext[i & 1] = 1;
    int y = ed[i].tar, temp = col[x] - 1 - (i & 1);
    temp += (temp >> 31) & 3;
    if (col[y] > 2)
      col[y] = temp, state |= dfs(y);
    else
      if (col[y] != temp)
        state |= 2;
  }
  return state | (ext[0] & ext[1]);
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    ed[++cntEdge] = Edge(y, h[x]), h[x] = cntEdge;
    ed[++cntEdge] = Edge(x, h[y]), h[y] = cntEdge;
  }
  
  long long ans = 0;
  memset(col + 1, 0x3f, sizeof(int) * n);
  for (int i = n; i; --i)
    if (col[i] > 2) {
      cntNode = cntEdge = tub[0] = tub[1] = tub[2] = 0, col[i] = 2;
      int state = dfs(i);
      if (state & 2)
        ans += 1ll * cntNode * cntNode;
      else
        if (state & 1)
          ans += 1ll * tub[0] * tub[1] + 1ll * tub[1] * tub[2] +
            1ll * tub[2] * tub[0];
        else
          ans += cntEdge >> 1;
    }
  for (int i = 1; i <= n; ++i)
    assert(col[i] >= 0 && col[i] < 3);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 7296
def main():
    a, b = map(int, input().split())

    if a == 0 or b == 0 or (a < 0 and b > 0):
        print("Zero")
    elif b < 0:
        if (a + b - 1) % 2 == 0:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")


if __name__ == "__main__":
    main()


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

using namespace std;
#define lli long long int
#define ff first
#define ss second
#define lld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef pair<int, int> pii;
typedef pair<long long int,long long int> pll;
const int nax=1000*1007;
#define INF 2e18
lli pow(lli x, lli y) { lli res = 1;while (y > 0) { if (y & 1) res = (res * x);  y = y >> 1; x = (x * x); } return res; } 
#define mod1 998244353

int main()
{
	IOS;
    lli n,k;
    cin>>n>>k;
    vector< pair<lli,lli> >v(k);
    for(int i=0;i<k;i++)
        cin>>v[i].ff>>v[i].ss;
    vector<lli>dp(n+1,0);
    vector<lli>dpsum(n+1,0);
    dp[1]=1;
    dpsum[1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            lli l = v[j].ff;
            lli r= v[j].ss;
            if(i-r >=1)
                dp[i] = ((dp[i]%mod1 + dpsum[i-l]%mod1)%mod1 - dpsum[i-r-1]%mod1 + mod1)%mod1;
            else if(i-l >=1)
                dp[i] = (dp[i]%mod1 + dpsum[i-l]%mod1)%mod1;
            else 
                continue;
        }
        dpsum[i] = (dpsum[i-1]%mod1 + dp[i]%mod1)%mod1;
    }
    cout<<dp[n]<<endl;
    
}

Measured memory_bytes: 6368
# https://atcoder.jp/contests/abc078/tasks/arc085_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, m = input_int_list()
    ans = (1900 * m + 100 * (n - m)) * 2**m
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61560
#include <iostream>

namespace ABC173
{

  class A_Payment
  {
  public:
    A_Payment() = default;
    ~A_Payment() = default;


    void Run()
    {
      int N = {};
      std::cin >> N;

      int hasuu = (N % 1000);

      std::cout << ((hasuu==0) ? 0 : (1000 - hasuu)) << std::endl;
    }
  };
}

int main()
{

  ABC173::A_Payment prob;
  prob.Run();

  return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[300];

bool judge(int x, int y, int z) {
    if (x == y || x == z || y == z) 
        return false;
    if (x + y > z && (abs(x  - y) < z)) {
        return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                if (judge(a[i], a[j], a[k])) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

//Super Star
public class Main{

	double[] smallestSphere(double[][] p){
		int n = p.length;
		double[] pos = new double[3];
		for(int i=0;i<n;i++)for(int j=0;j<3;j++)pos[j]+=p[i][j];
		for(int j=0;j<3;j++)pos[j]/=n;
		double ratio = 0.5;
		while(ratio > 1e-8){
			for(int t=0;t<50;t++){
				double max = -1;
				int id = -1;
				for(int i=0;i<n;i++){
					double d = 0;
					for(int j=0;j<3;j++)d+=(pos[j]-p[i][j])*(pos[j]-p[i][j]);
					if(max < d){
						max = d; id = i;
					}
				}
				double dx = p[id][0]-pos[0], dy = p[id][1]-pos[1], dz = p[id][2]-pos[2];
				pos[0]+=dx*ratio;
				pos[1]+=dy*ratio;
				pos[2]+=dz*ratio;
			}
			ratio/=2;
		}
		return pos;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			double[][] p = new double[n][3];
			for(int i=0;i<n;i++)for(int j=0;j<3;j++)p[i][j]=sc.nextDouble();
			double[] c = smallestSphere(p);
			double res = 0;
			for(int i=0;i<n;i++){
				double d = 0;
				for(int j=0;j<3;j++)d+=(c[j]-p[i][j])*(c[j]-p[i][j]);
				res = Math.max(res, d);
			}
			System.out.printf("%.8f\n", Math.sqrt(res));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<stdio.h>

int main()
{
	int x, y;
	int i, i2;

	for (i = 1; i < 10; i++)
	{
		for (i2 = 1; i2 < 10; i2++)
		{
			printf("%dx%d=%d\n", i,i2,i*i2);
		}
	}

	return 0;
}

Measured memory_bytes: 1820
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<ll> g[maxn];
bool used[maxn];
ll a[maxn], ans[maxn], kek[maxn];

vector<ll> d;
vector<vector<ll>> dd;
ll lst = 0;

void go(ll u) {
	ll id = lower_bound(all(d), a[u]) - begin(d);
	kek[u] = id;
	dd[id].push_back(u);
	d[id] = a[u];
	if (id > lst) lst = id;
}

void un(ll u) {
	ll id = kek[u];
	dd[id].pop_back();
	if (dd[id].empty()) {
		d[id] = LLONG_MAX;
		lst--;
	} else d[id] = a[dd[id].back()];
}

void dfs(ll u) {
	used[u] = 1;
	go(u);
	ans[u] = lst;
	for (ll v : g[u]) {
		if (used[v]) continue;
		dfs(v);
	}
	un(u);
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	d.resize(maxn, LLONG_MAX);
	dd.resize(maxn);

	ll n; cin >> n;
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n - 1; i++) {
		ll u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1);

	for (ll i = 1; i <= n; i++) {
		cout << ans[i] + 1 << '\n';
	}

	return 0;
}

/*

*/

Measured memory_bytes: 41424
#! -*- coding: utf-8 -*-
import numpy as np

n = int(raw_input())

p = np.zeros([n],int)
for i in range(n):
    p[i] = int(raw_input())

count = np.zeros([n+1],int)

for i in range(n):
    count[p[i]] = count[p[i]-1]+1

#print count

#print count

#print np.max(count)

ans = n-np.max(count)

print ans


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    int ans = INT_MAX;
    for(int i = x.at(0); i <= x.at(n-1); i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += pow((x.at(j) - i),2);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque


def main():
    n = int(input())
    tree = AdjacentListGraph([Vertex() for _ in range(n)])
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        tree.add_edge(a - 1, b - 1, c)
        tree.add_edge(b - 1, a - 1, c)
    q, k = map(int, input().split())
    distances = distances_from(tree, k - 1)
    # print(distances)
    answers = []
    for _ in range(q):
        x, y = map(int, input().split())
        answers.append(distances[x - 1] + distances[y - 1])
    print("\n".join(map(str, answers)))


def distances_from(
    graph: "Graph", from_: int, break_if=lambda node: False
) -> "List[int]":
    distances = [None for _ in range(graph.size)]
    distances[from_] = 0
    queue = deque([from_])
    while queue:
        node = queue.popleft()
        if break_if(node):
            break
        curDist = distances[node]
        for edge in graph.edges_from(node):
            if distances[edge.to] is not None:
                continue
            delta = edge.weight if edge.weight else 0
            distances[edge.to] = curDist + delta
            queue.append(edge.to)
    return distances


class Vertex:
    __slots__ = ("data", "edges")

    def __init__(self, data=None):
        self.data = data
        self.edges = set()

    def add_edge(self, to, weight=None):
        self.edges.add(Edge(to, weight))

    def remove_edge(self, to: int) -> bool:
        for i, edge in enumerate(self.edges):
            if edge.to == to:
                del self.edges[i]
                return True
        return False


class Edge:
    __slots__ = ("to", "weight")

    def __init__(self, to, weight=None):
        self.to = to
        self.weight = weight

    def __hash__(self) -> int:
        return hash(self.to)

class AdjacentListGraph:
    def __init__(self, vertices):
        self.vertices = vertices
        self.size = len(vertices)

    def get_weight(self, from_: int, to: int):
        for edge in self.vertices[from_].edges:
            if edge.to == to:
                return edge.weight
        return None

    def edges_from(self, from_: int):
        return self.vertices[from_].edges

    def add_edge(self, from_: int, to: int, weight=None) -> bool:
        return self.vertices[from_].add_edge(to, weight)

    def remove_edge(self, from_: int, to: int) -> bool:
        return self.vertices[from_].remove_edge(to)

    def is_adjacent(self, from_: int, to: int) -> bool:
        return to in {edge.to for edge in self.edges_from(from_)}


if __name__ == "__main__":
    main()


Measured memory_bytes: 70968
#include <bits/stdc++.h>
#define N 2005
using namespace std;
typedef pair<int,int> P;
typedef set<int>::iterator it;
int n,k,q,a[N],tree[N],ans=1e9;
P b[N];
void add(int x,int value)
{
    for(;x<=n+1;x+=x&-x)
        tree[x]+=value;
}
int get(int x)
{
    int res=0;
    for(;x;x-=x&-x)
        res+=tree[x];
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i].first=a[i];
        b[i].second=i;
    }
    sort(b+1,b+1+n);
    for(int s=1;s<=n;s++){
        for(int i=1;i<=n+1;i++)
            tree[i]=0;
        set<int>st1,st2;int amt=0;
        st1.insert(0);st1.insert(n+1);
        st2.insert(0);st2.insert(-n-1);
        for(int i=1;i<=s-1;i++){
            st1.insert(b[i].second);
            st2.insert(-b[i].second);
        }
        for(int i=s;i<=n;i++){
            int r=*st1.lower_bound(b[i].second);
            int l=-*st2.lower_bound(-b[i].second);
            //cout<<b[s].first<<" : "<<b[i].first<<" "<<l<<" "<<r<<" at "<<b[i].second<<" 1"<<endl;
            r=r+get(r);
            l=l+get(l);
            //cout<<b[s].first<<" to "<<b[i].first<<" : "<<l<<" "<<r<<" at "<<b[i].second<<" "<<endl;
            if(r-l-1<k){
                st1.insert(b[i].second);
                st2.insert(-b[i].second);
                continue;
            }
            amt++;
            add(b[i].second+1,-1);
            //cout<<b[s].first<<" use "<<b[i].first<<" "<<l<<" "<<r<<" at "<<b[i].second<<" "<<endl;
            if(amt==q){
                //cout<<b[s].first<<" - "<<b[i].first<<" "<<b[i].first-b[s].first<<endl;
                ans=min(ans,b[i].first-b[s].first);
                break;
            }
        }
    }
    cout<<ans;
    return 0;
}


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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}
//you don't know math, unless you can do math!
int OO = 1e7;

int main() {

    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    string o,e; cin>>o>>e;

    int l = min(o.length(), e.length());
    loop(i, l)
        cout<<o[i]<<e[i];

    if(o.length() > e.length()) cout<<o[o.length()-1];
    if(e.length() > o.length()) cout<<e[e.length()-1];


}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Data
{
public:
    int id, score;
    Data(int id, int score){
        this->id = id;
        this->score = score;
    }
    bool operator<(const Data& d) const{
        return make_pair(-score, id) < make_pair(-d.score, d.id);
    }
};

int main()
{
    int n, r, l;
    cin >> n >> r >> l;

    vector<int> score(n, 0);
    vector<int> tvTime(n, 0);
    set<Data> s;
    for(int i=0; i<n; ++i)
        s.insert(Data(i, 0));

    vector<int> d(r), t(r), x(r);
    for(int i=0; i<r; ++i){
        cin >> d[i] >> t[i] >> x[i];
        -- d[i];
    }

    int k = 0;
    for(int i=1; i<=l; ++i){
        ++ tvTime[s.begin()->id];
        while(k < r && t[k] == i){
            s.erase(Data(d[k], score[d[k]]));
            score[d[k]] += x[k];
            s.insert(Data(d[k], score[d[k]]));
            ++ k;
        }
    }

    int ret = 0;
    for(int i=0; i<n; ++i){
        if(tvTime[i] > tvTime[ret])
            ret = i;
    }
    cout << (ret + 1) << endl;

    return 0;
}

Measured memory_bytes: 14136
#include <bits/stdc++.h>
using namespace std;
int a[55];
int main()
{
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m;i++){
    int c, b;
    cin >> c >> b;
    a[c]++;
    a[b]++;
  }
  for (int i = 1; i <= n; i++){
    cout << a[i] << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,c[50],y[50],ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	for(int i=0;i<n;i++){
		cin>>y[i];
	}
	for(int i=0;i<n;i++){
		if(c[i]>y[i]){
			ans+=c[i]-y[i];
		}
	}
	cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    ll ret = 0;
    if (K == 10) {
        ret = 1;
        while (N >= 10) {
            N /= 10;
            ret ++;
        }
        cout << ret << endl;
        return 0;
    }
    ll n = 1;
    if (N < K) {
        cout << 1 << endl;
        return 0;
    }
    while(N >= n) {
        ret ++;
        n *= K;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    vector<vector<int>> a (3, vector<int> (3));
    rep(i,3){
        rep(j,3){
            cin >> a[i][j] ;
        }}
    int  n ;
    cin >> n;
    vector<int> b (n);
    rep(i, n){
        cin >> b[i];
    }
    bool bingo = false ;

    rep(j,3){ 
        int num = 0;
    rep(i,3){

        rep(k,n){
        if (
            a[j][i] == b[k]){
                num++ ;
            }


            }}
                    if (num == 3){
            bingo = true ;
        }}
    rep(j,3){ 
        int num = 0;
    rep(i,3){

        rep(k,n){
        if (
            a[i][j] == b[k]){
                num++ ;
            }


            }}
            if (num == 3){
            bingo = true ;
        }}
    int num2 = 0;
    rep(i,3){
        rep(k,n){
        if(a[i][i] == b[k]){
            num2++ ;
        }
    }}
    if (num2 == 3){
        bingo = true;
    }
    int num3 = 0 ;
    rep(i,3){
            rep(k, n){
        if(a[i][3 - i - 1] == b[k]){
            num3++ ;  
        }

        }
    }
    if (num3 == 3){
        bingo = true;
    }
 if (bingo) {
     cout << "Yes" << endl;
 }
 else {
     cout << "No" << endl;
 }
}
    
    


Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappush, heappop


def solve(n_query, q_query, k):
    d = defaultdict(list)
    for a, b, c in n_query:
        d[a].append((c, b))
        d[b].append((c, a))

    from_k = dijkstra(n+1, d, k)
    ans = []
    for x, y in q_query:
        x_to_k = from_k[x]
        k_to_y = from_k[y]

        ans.append(x_to_k + k_to_y)
    #    print("{0}->{1}: {2} |{3}->{4}: {5}".format(x, k, x_to_k, k, y, k_to_y))

    return ans


def dijkstra(vertex, g, sp):
    d = [float('inf')] * vertex
    d[sp] = 0
    heap = [(d[sp], sp)]

    while heap:
        du, u = heappop(heap)
        for length, v in g[u]:

            if d[v] > du + length:
                d[v] = du + length
                heappush(heap, (d[v], v))
    return d


if __name__ == '__main__':
    n = int(input())
    par, rank = [-1]*(n+1), [0]*(n+1)
    diff_weight = [0]*(n+1)
    is_via_root = [1]*(n+1)
    n_query = []
    q_query = []

    for _ in range(n-1):
        a, b, c = map(int, input().split())
        n_query.append((a, b, c))
    q, k = map(int, input().split())
    for _ in range(q):
        x, y = map(int, input().split())
        q_query.append((x, y))

    ans = solve(n_query, q_query, k)
    for a in ans:
        print(a)


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

int main(){
    ll n;
    cin>>n;
    vector<ll> a(3*n);
    rep(i,3*n) cin>>a[i];
    sort(a.begin(),a.end());
    ll sum=0;
    rep(i,n) sum+=a[n+2*i];
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 5548
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;
const int INF = 1e9;

class TaskB {
private:
	Debugger debugger;
	vector<int> dx = {0,0,1,-1};
	vector<int> dy = {1,-1,0,0};

public:
	void solveOne(int it){
		int n;
		cin >> n;
		vector<int> vals(n*n);
		for(int i = 0; i < n*n; i++){
			cin >> vals[i];
		}
		vector<vector<int>> dist(n, vector<int>(n, INF));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				dist[i][j] = min(min(i,n-i-1), min(j,n-j-1));
			}
		}

		vector<vector<int>> cost(n, vector<int>(n, 1));
		int ans = 0;
		for(int i = 0; i < n * n; i++){
			vals[i]--;
			int x = vals[i] / n;
			int y = vals[i] % n;
			ans += dist[x][y];
			cost[x][y] = 0;
			deque<pair<int,int>> dq;
			dq.push_front({x,y});
			while(!dq.empty()){
				x = dq.front().first;
				y = dq.front().second;
				dq.pop_front();
				for(int dir = 0; dir < 4; dir++){
					int xnew = dx[dir] + x;
					int ynew = dy[dir] + y;
					if(xnew >= n or xnew < 0 or ynew >= n or ynew < 0){
						continue;
					}
					if(cost[x][y] + dist[x][y] < dist[xnew][ynew]){
						dist[xnew][ynew] = cost[x][y] + dist[x][y];
						if(cost[xnew][ynew] == 0){
							dq.push_front({xnew,ynew});
						}else{
							dq.push_back({xnew,ynew});
						}
					}
				}
			}
		}

		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskB solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 7180
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

N = int(input())
A = tuple(int(input()) for _ in range(N))

"""
0: zero_L
1: even_L
2: odd
3: even_R
4: zero_R
"""
dp = [inf] * 5
for i, a in enumerate(A):
    if i == 0:
        if a == 0:
            dp[0] = a
            dp[1] = 2
            dp[2] = 1
            dp[3] = 2
            dp[4] = a
        elif a % 2 == 0:
            dp[0] = a
            dp[1] = 0
            dp[2] = 1
            dp[3] = 0
            dp[4] = a
        else:
            dp[0] = a
            dp[1] = 1
            dp[2] = 0
            dp[3] = 1
            dp[4] = a
        continue

    newDP = [inf]*5
    if a == 0:
        newDP[0] = dp[0] + a
        newDP[1] = min(dp[0], dp[1]) + 2
        newDP[2] = min(dp[0], dp[1], dp[2]) + 1
        newDP[3] = min(dp[0], dp[1], dp[2], dp[3]) + 2
        newDP[4] = min(dp[0], dp[1], dp[2], dp[3], dp[4]) + a
    elif a % 2 == 1:
        newDP[0] = dp[0] + a
        newDP[1] = min(dp[0], dp[1]) + 1
        newDP[2] = min(dp[0], dp[1], dp[2])
        newDP[3] = min(dp[0], dp[1], dp[2], dp[3]) + 1
        newDP[4] = min(dp[0], dp[1], dp[2], dp[3], dp[4]) + a
    else:
        newDP[0] = dp[0] + a
        newDP[1] = min(dp[0], dp[1])
        newDP[2] = min(dp[0], dp[1], dp[2]) + 1
        newDP[3] = min(dp[0], dp[1], dp[2], dp[3])
        newDP[4] = min(dp[0], dp[1], dp[2], dp[3], dp[4]) + a
    dp = newDP

print(min(dp))

Measured memory_bytes: 17060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<PII, null_type, less<PII>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to k'th element (0-based), order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 2500 + 10;

struct Edge {
    int vertex, cost;
};

int n, m, p;
vector<Edge> fwd[N];
vector<int> bwd[N];
bool reachable_from_n[N];
LL dis[N];

void dfs(int u) {
    reachable_from_n[u] = true;
    for (int v : bwd[u]) {
        if (!reachable_from_n[v]) {
            dfs(v);
        }
    }
}

void bellman_ford() {
    for (int u = 1; u <= n; u++) {
        dis[u] = LINF;
    }
    dis[1] = 0;
    REP(rep, n-1) {
        for (int u = 1; u <= n; u++) {
            if (dis[u] == LINF)
                continue;
            for (Edge e : fwd[u]) {
                int v = e.vertex;
                int c = e.cost;
                if (dis[u] + c < dis[v]) {
                    dis[v] = dis[u] + c;
                }
            }
        }
    }
}

bool negative_cycle() {
    for (int u = 1; u <= n; u++) {
        if (dis[u] == LINF)
                continue;
        for (Edge e : fwd[u]) {
            int v = e.vertex;
            int c = e.cost;
            if (dis[u] + c < dis[v]) {
                if (reachable_from_n[v]) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    cin >> n >> m >> p;
    REP(rep, m) {
        int u, v, c;
        cin >> u >> v >> c;
        fwd[u].push_back({v, p - c});
        bwd[v].push_back(u);
    }
    dfs(n);
    bellman_ford();
    if (negative_cycle()) {
        cout << -1 << '\n';
    } else {
        cout << max(-dis[n], 0LL) << '\n';
    }
}






























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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int a[N];
int n;
int dp[N];

int solve(int i)
{
	if(i>=n)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	if(i<n-1)
	{
		dp[i] =  min( abs(a[i+1]-a[i]) +solve(i+1), abs(a[i+2]-a[i]) + solve(i+2));		
		return dp[i];
	}
	else
	{
		dp[i] =  abs(a[n] - a[i]) + solve(i+1);
		return dp[i];
	}
		
}

int32_t main()
{
	IOS;
	memset(dp,-1,sizeof(dp));
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
	}
	cout << solve(1) << endl;
}


Measured memory_bytes: 3456
#include <iostream>

using namespace std;

int A[300000];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int t = 0;
	long int res = 0;
	int sub = 0;
	for (int s = 0; s < N; s++) {
		while ((sub + A[t] == (sub ^ A[t])) && t < N) {
			sub ^= A[t++];
			//cout << sub << endl;
		}
		res += t - s;
		sub ^= A[s];
	}
	cout << res << endl;
	//cout << (7 & ~2) << endl;
	//system("pause");
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int odds = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		odds += a % 2;
	}
	if (odds % 2 == 1) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N_MAX = 100001;
typedef pair<int,int> P;
int main()
{
  int n,i,j,k,u,v,a,b,d,res;
  P du[N_MAX],dv[N_MAX];
  vector<int> ve[N_MAX];
  queue<int> q;
  cin >> n >> u >> v;
  for(i=1;i<=n;i++){
    du[i]=P(-1,i);
    dv[i]=P(-1,i);
  }
  for(i=0;i<n-1;i++){
    cin >> a >> b;
    ve[a].push_back(b);
    ve[b].push_back(a);
  }
  q.push(v);
  dv[v].first=0;
  while(q.size()){
    j=q.front(); q.pop();
    for(k=0;k<ve[j].size();k++)
      if(dv[ve[j][k]].first==-1){
        dv[ve[j][k]].first=dv[j].first+1;
        q.push(ve[j][k]);
      }
  }
  q.push(u);
  du[u].first=0;
  while(q.size()){
    j=q.front(); q.pop();
    for(k=0;k<ve[j].size();k++)
      if(du[ve[j][k]].first==-1){
        du[ve[j][k]].first=du[j].first+1;
        q.push(ve[j][k]);
      }
  }
  sort(dv+1,dv+n+1,greater<P>());
  for(i=1;i<=n;i++){
    d=dv[i].first;
    j=dv[i].second;
    if(du[j].first<d){
      res=d-1;
      cout << res << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 7424
import math
a , b = map(int, input().split(" "))
c = 0
ans = 0
if(b == 1):
    print(0)
else:
    for i in range(0, 50):
        if(i == 0):
            c = c + a
            ans = ans + 1
        else:
            c = c + a - 1
            ans = ans + 1
        if(c >= b):
            break
    print(ans)

Measured memory_bytes: 3064
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

a,b,c = m()

k = onem()

po = cl.deque([[a,b,c,k]])
final = []
while len(po) != 0:
	a,b,c,k = po.popleft()
	if k == 0:
		final.append([a,b,c])
		continue
	po.append([a*2,b,c,k-1])
	po.append([a,b*2,c,k-1])
	po.append([a,b,c*2,k-1])
for i in range(len(final)):
	if final[i][0] < final[i][1] and final[i][1] < final[i][2]:
		print("Yes")
		exit()
print("No")


Measured memory_bytes: 70856
import heapq
import sys
sys.setrecursionlimit(2000)
def A():
    T = int(input())
    for i in range(T):
        N, A, B, C, D = map(int, input().split())
        memo = {}
        def dfs(n):
            if n == 0:
                return 0
            if n == 1:
                return D
            if n in memo:
                return memo[n]
            l2 = (n//2)*2
            r2 = ((n+1)//2)*2
            l3 = (n//3)*3
            r3 = ((n+2)//3)*3
            l5 = (n//5)*5
            r5 = ((n+4)//5)*5
            res = n*D
            res = min(res, abs(n-l2)*D+A+dfs(l2//2))
            res = min(res, abs(n-r2)*D+A+dfs(r2//2))
            res = min(res, abs(n-l3)*D+B+dfs(l3//3))
            res = min(res, abs(n-r3)*D+B+dfs(r3//3))
            res = min(res, abs(n-l5)*D+C+dfs(l5//5))
            res = min(res, abs(n-r5)*D+C+dfs(r5//5))
            memo[n] = res
            return res
        print(dfs(N))
        # q = [(D, 1)] #increase by 1 is necessary cuz cant multiply by 0
        # heapq.heapify(q)
        # visited = set()
        # while True:
        #     # print(q)
        #     cost, cur = heapq.heappop(q)
        #     if cur == N:
        #         print(cost)
        #         break
        #     visited.add(cur)
        #     elif cur < N:
        #         if cur*2 not in visited:
        #             t = (cost+min(cur*D, A), cur*2)
        #             if t not in q:
        #                 heapq.heappush(q, t)
        #         if cur*3 not in visited:
        #             t = (cost+min(cur*2*D, B), cur*3)
        #             if t not in q:
        #                 heapq.heappush(q, t)
        #         if cur*5 not in visited:
        #             t = (cost+min(cur*4*D, C), cur*5)
        #             if t not in q:
        #                 heapq.heappush(q, t)
        #         if cur+1 not in visited:
        #             if (cost+D, cur+1) not in q:
        #                 heapq.heappush(q, (cost+D, cur+1))
        #     if cur > 0 and cur-1 not in visited:
        #         if (cost+D, cur-1) not in q:
        #             heapq.heappush(q, (cost+D, cur-1))
A()
# N = (2**a+d)*(3**b+e)*(5**c+d)+f
# minimize(a*A+b*B+c*C+*d+e+f)

Measured memory_bytes: 10932
a = list(map(int,input().split()))
ans = 0
if a[0]>a[1]:
  ans += a[0]
  a[0] -= 1
else:
  ans += a[1]
  a[1] -= 1
if a[0]>a[1]:
  ans += a[0]
else:
  ans += a[1]
print(ans)



Measured memory_bytes: 9148
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int a[100000];
	f(i, 100000)a[i] = 0;
	int k, s;
	int n, m;
	int x, y, z;
	int ans = 0;

	scanf("%d", &n);
scanf("%d",&m);

	ans = 2 * m - n;
	printf("%d\n", ans);

	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> dp(2,vector<int>(N,0));
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(i==0){
      dp.at(0).at(i)=x;
    }else{
      dp.at(0).at(i)=dp.at(0).at(i-1)+x;
    }
  }
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(i==0){
      dp.at(1).at(i)=dp.at(0).at(i)+x;
    }else{
      dp.at(1).at(i)=max(dp.at(1).at(i-1),dp.at(0).at(i))+x;
    }
  }
  
  cout<<dp.at(1).at(N-1)<<endl;
}

Measured memory_bytes: 256
function Main(input){
var N = input.split("\n")[0];
N = parseInt(N,10);
var H = input.split("\n")[1].split(" ");
var count = 1;
var a;
for(i=0;i<=(H.length-1);i++){
  H[i] = parseInt(H[i],10);
}
for(i=1;i<=(H.length-1);i++){
  for(j=0;j<=(H.length-1);j++){
    if(i==j){
      break;
    }else{
      if(H[i]>=H[j]){
        a = true;
      }else if(H[i]<=H[j]){
        a = false;
        break;
      }
    }
  }
  if(a==true){
    count += 1;
  }
}
console.log(count);
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  vector<int> st;
  set<int> en;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(a == 0)st.pb(b);
    if(b == n - 1)en.insert(a);
  }
  for(int a: st){
    if(en.find(a) != en.end()){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 5368
#include<cstdio>
#include<cstring>
#define MAXL 200000

int len,last;
long long ans;
char s[MAXL+3];

int main() {
	scanf("%s",s);
	len=strlen(s);
	for(int i=0;i<len;i++)
		if(s[i]=='W')
			ans+=i-last,last++;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, k;
int arr[103];
int dp[(int)1e5 + 3];

int solve(int remK)
{
    int &ret = dp[remK];
    if(~ret)
        return ret;
    ret = false;
    for(int i = 1; i <= n; i++)
    {
        if(remK - arr[i] < 0)
            break;
        ret = ret | (solve(remK - arr[i]) == false);
    }
    return ret;
}

int main()
{
    IO;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    memset(dp, -1, sizeof dp);
    if(solve(k))
        cout << "First";
    else
        cout << "Second";
    return 0;
}


Measured memory_bytes: 5376
N,*P=map(int,open(0).read().split());c=0
ranged=lambda:any(i+1==P[i]for i in range(N))
while ranged():
 for i in range(N-1):
  if i+1==P[i]and i+2==P[i+1]:P[i],P[i+1]=P[i+1],P[i];c+=1
 for i in range(N-1):
  if i+1==P[i]or i+2==P[i+1]:P[i],P[i+1]=P[i+1],P[i];c+=1
print(c)

Measured memory_bytes: 14324
#include<iostream>
#include<sstream>

using namespace std;

int main(){
  int N,T;
  cin>>N>>T;
  int c=0;
  stringstream ss;
  int l=99999;
  while(N--){
    int h1,m1,h2,m2;
    char s1[51],s2[51];
    char d1,d2;
    cin>>h1>>d1>>m1>>s1>>h2>>d2>>m2>>s2;
    int i=h1*60+m1-l;
    if(i>=T){
      c++;
      ss<<s1<<' '<<i<<endl;
    }
    l=h2*60+m2;
  }
  cout<<c<<endl;
  cout<<ss.str();
}

Measured memory_bytes: 1232
n = int(input())
A = list(map(int,input().split()))
alice = 0
bob = 0
A = sorted(A)
for i in range(n):
    if i % 2 == 0:
        alice += A[n - 1 - i]
    else:
        bob += A[n - 1 - i]
print(alice - bob)


Measured memory_bytes: 9048
#include <iostream>
#include <cstring>
#include <cstdio>
#define ll long long
using namespace std;

inline int read(){
	int sum=0,f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0'){sum=sum*10+c-'0';c=getchar();}
	return f*sum;
}

const int N=2005;
const int Mod=924844033;
int n,K,tot,a[N],v[N];
ll f[N][N][2][2],fac[N]={1};

signed main(){
	n=read();K=read();
	a[0]=-(1<<30);
	for(int i=1;i<=n;i++)
		if(!v[i]) 
			for(int j=i;j<=n;j+=K) a[++tot]=j,v[j]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%Mod;
	f[0][0][0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0][0][0]=1;
		for(int j=1;j<=i;j++){
			f[i][j][0][0]=(f[i-1][j][0][0]+f[i-1][j][1][0]+(a[i]-a[i-1]==K)*f[i-1][j-1][0][0]%Mod)%Mod;
			f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+(a[i]-a[i-1]==K)*f[i-1][j-1][0][1]%Mod)%Mod;
			f[i][j][0][1]=((f[i-1][j-1][0][0]+f[i-1][j-1][1][0])*(a[i+1]-a[i]==K))%Mod;
			f[i][j][1][1]=((f[i-1][j-1][0][1]+f[i-1][j-1][1][1])*(a[i+1]-a[i]==K))%Mod;
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++){
		int sum=f[n][i][0][0]+f[n][i][0][1]+f[n][i][1][0]+f[n][i][1][1];
		sum%=Mod;
		ans=(ans+sum*fac[n-i]%Mod*(i&1? -1:1))%Mod;
		ans=(ans+Mod)%Mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 123776
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
int main(void) {
	
       int n,k;
       scanf("%d%d",&n,&k);
       int l[n],i;
       for(i=0;i<n;++i)
            scanf("%d",&l[i]);
  
       sort(l,l+n);
        int sum=0;
  for(i=n-1;i>=n-k;--i)
        sum+=l[i];
  
  printf("%d",sum);
	          
	return 0;
}

Measured memory_bytes: 128
import math, sys

N = int(input())

sqrt_n = round(math.sqrt(N))
# print(sqrt_n)

min_f = sys.maxsize
for i in range(sqrt_n, 0, -1):
    if N % i == 0:
        len_A = len(str(i))
        len_B = len(str(N//i))
        F = max(len_A, len_B)
        min_f = min(min_f, F)

print(min_f)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 200005;
const int mod = (int) 1e9 + 7;

int n;
int arr[N];
int cnt[N];
int dp[N];
bool used[N];

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}

int main() {
  cin >> n;
  vector <int> vec{0};
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != arr[i - 1]) {
      vec.push_back(arr[i]);
    }
  }
  map <int, int> cn;
  for (int i = 1; i < vec.size(); i++) {
    int x = vec[i];
    if (!used[x]) {
      add(dp[i], dp[i - 1]);
      used[x] = 1;
    } else {
      add(dp[i], dp[i - 1]);
      add(dp[i], (cn[x] + cnt[x]) % mod);
    }
    cn[x]++;
    add(cnt[x], dp[i - 1]);
    //cout << i << " " << vec[i] << " " << ans << " " << cnt[x] << endl;
  }
  add(dp[vec.size() - 1], 1);
  cout << dp[vec.size() - 1] << endl;
  return 0;
}


Measured memory_bytes: 12916
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main(){

    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    map <char, int> M;

    for (int i = 0; i < N; i++){
        if (M[S[i]] == 0){
            count ++;
        }
        M[S[i]]++;
    }

    vector <int> A;
    for (int i = 'a'; i <= 'z'; i++){
        if (M[i] != 0){
            A.push_back(M[i]);
        }
    }

    long long max = 1000000007;
    long long ans = 1;

    for (int i = 0; i < count; i++){
        ans = ans * (A[i] + 1);
        if (i == count - 1){
            ans -= 1;
        }
        ans = ans % max;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	int n;
	cin>>n;
	if(n>29)cout<<"Yes\n";
	else cout<<"No\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 3628
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t1,t2 = inp
a = inp
b = inp
if(a[0] > b[0])
  a,b = b,a
end
if((a[0]-b[0])*(a[1]-b[1])>=0)
  puts 0
  exit
end
kyoa = a[0] * t1 + a[1] * t2
kyob = b[0] * t1 + b[1] * t2
if(kyoa == kyob )
  puts "infinity"
  exit
end
sa = kyoa - kyob
if(kyoa > kyob)
  sa1 = -a[0]*t1+b[0]*t1
  nk = sa1/sa
  ko_last = (nk*kyob+b[0]*t1 == nk*kyoa+a[0]*t1)? 1 : 0
  p sa1/sa*2 + 1 - ko_last
else
  p 0
end

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
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; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
 
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,m;
  cin>>n>>m;
  
  vi x(m);
  rep(i,m)cin>>x[i];
  
  if(m==1 || n>=m){
    cout(0); return 0;
  }
  
  vsort(x);
  vi diffs(m-1);
  rep(i,m-1)diffs[i]=x[i+1]-x[i];
  rvisort(diffs);
  ll ans=vtotal(diffs);
  rep(i,n-1){
    ans-=diffs[i];
  }
  cout(ans);
}

Measured memory_bytes: 1024