akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;


int main() {
	cin >> N >> M;
	vector<vector<int>> s(M);
	for (int i = 0; i < M; i++) {
		cin >> K;
		vector<int> tmp(K);
		for (int j = 0; j < K; j++) {
			cin >> tmp[j];
			tmp[j]--;
		}
		s[i] = tmp;
	}
	vector<int> p(M);
	for (int i = 0; i < M; i++)cin >> p[i];

	for (int bit = 0; bit < (1 << N); bit++) {
		int num_on = 0;
		for (int i = 0; i < M; i++) {
			int tmp = 0;
			for (int j = 0; j < s[i].size(); j++) {
				if (bit&(1 << s[i][j])) {
					tmp++;
				}
			}
			if (tmp % 2 == p[i]) {
				num_on++;
			}
			else break;
		}
		if (num_on == M)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		City[] c = new City[m];
		for(int i = 0; i < m; i++) {
			c[i] = new City(sc.nextInt(), sc.nextInt(), i);
		}
		Arrays.sort(c, (c1, c2) -> c1.y - c2.y);
		int pnum[] = new int[n + 1];
		Arrays.fill(pnum, 1);
		for(int i = 0; i < m; i++) {
			c[i].setNum(pnum[c[i].p]);
			pnum[c[i].p]++;
		}
		Arrays.sort(c, (c1, c2) -> c1.i - c2.i);
		for(int i = 0; i < m; i++) c[i].printNumber();
		
		
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}
	public class City {
		int p, y, i, num;
		int getY() {
			return y;
		}
		void setNum(int num) {
			this.num = num;
		}
		City(int p, int y, int i){
			this.p = p; this.y = y;this.i = i;
		}
		void printNumber(){
			String s1 = "000000";
			String s2 = "000000";
			s1 = s1 + Integer.toString(p);
			s2 = s2 + Integer.toString(num);
			System.out.println(s1.substring(s1.length() - 6) + s2.substring(s2.length() - 6));
		}
	}
}



Measured memory_bytes: 113804
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val S = next()
    val T = next()
    var ans = 0
    for (i in S.indices) {
        if (S[i] != T[i]) ans++
    }
    println(ans)
}

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

struct edge {
  int to, cost;
};

vector<edge> G[200010];
bool vis[100010];
int d[100010];

bool dfs(int v, int dist) {
  if (vis[v]) {
    if (d[v] != dist) {
      return true;
    } else {
      return false;
    }
  }

  vis[v] = true;
  d[v] = dist;

  for (int i = 0; i < (int)G[v].size(); i++) {
    if (dfs(G[v][i].to, d[v] + G[v][i].cost)) {
      return true;
    }
  }

  return false;
}

int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    G[l].push_back({r,d});
    G[r].push_back({l,-d});
  }

  for (int i = 0; i < n; i++) {
    if (!vis[i] && dfs(i, 0)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;

}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define mod 1000000007
#define lli long long int
using namespace std;
void GetSol()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (a[i] + a[j] > a[k] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        GetSol();
    }
    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <stdlib.h>

#define NOT_FOUND -1

int linearSearch(int array[], int length, int key) {
    for (int i = 0; i < length; i++)
        if (array[i] == key)
            return i;
    
    return NOT_FOUND;
}

int main(int argc, char** argv) {
    int nNumbers;
    
    // set S
    scanf("%d", &nNumbers);
    
    const int nS = nNumbers;
    int S[nS];
    
    for (int iS = 0; iS < nS; iS++)
        scanf("%d", &S[iS]);
    
    // set T
    scanf("%d", &nNumbers);
    
    const int nT = nNumbers;
    int T[nT];
    
    for (int iT = 0; iT < nT; iT++)
        scanf("%d", &T[iT]);
    
    // do the magic
    int nIntersect = 0;
    for (int iT = 0; iT < nT; iT++)
        if (linearSearch(S, nS, T[iT]) != NOT_FOUND) 
            nIntersect++;
    
    printf("%d\n", nIntersect);

    return (EXIT_SUCCESS);
}




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

using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s)
{
    return '"' + s + '"';
}

string to_string(const char* s)
{
    return to_string((string) s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out()
{
    cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    long long ans = 0;
    int w = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] < w)
        {
            ans += w - a[i];
        }
        w = max(w, a[i]);
    }
    cout << ans;
    return 0;
}



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



int main()
{
	int a, b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int ans=min(a,b)+min(c,d);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 764
using System;

namespace AtCoder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] data;
            data = new int[6];
            for(int i = 0; i < 6; i++)
            {
                data[i] = int.Parse(Console.ReadLine());
            }
            int k = data[5];
            bool flag = true;

            for(int i = 0; i < 5; i++)
            {
                for(int j = i + 1; j < 5; j++)
                {
                    if(data[j] - data[i] > k)
                    {
                        flag = false;

                    }
                }
            }
            if(flag)
            {
                Console.WriteLine("Yay!");

            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;

const int N = 500;
const ll mod = 1e9 + 7;             

int n;
int can[N][N];
ll dp[24][(1 << (21))];
vector<int> bits[24];

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

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

	for(int i = 0;i < (1 << n);i++){
		bits[__builtin_popcount(i)].push_back(i);
	}

	dp[0][0] = 1;
	for(int i = 1;i <= n;i++){
		for(int h: bits[i - 1]){
			//cerr << i << " " << h << "\n";
			for(int k = 0;k < n;k++){
				if(!((h >> k) & 1)){
					if(can[i][k + 1]){
						int newh = h + (1 << k);
						dp[i][newh] = (dp[i][newh] + dp[i - 1][h]);
						if(dp[i][newh] >= mod)
							dp[i][newh] %= mod;
					}
				}
			}
		}	
	}

	cout << dp[n][(1 << n) - 1];
}

Measured memory_bytes: 320956
using System;
using System.Linq;

namespace ABC086
{
    class C
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var t_now = 0;
            var x_now = 0;
            var y_now = 0;
            var res = "Yes";
            for (int i = 0; i < N; i++)
            {
                var plan = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var dest_t = plan[0];
                var dest_x = plan[1];
                var dest_y = plan[2];
                var duration = dest_t - t_now;
                var dist = Math.Abs(dest_x - x_now) + Math.Abs(dest_y - y_now);
                var loss_time = duration - dist;
                if (loss_time < 0 || loss_time %2 ==1)
                {
                    res = "No";
                    break;
                }
                else
                {
                    t_now = dest_t;
                    x_now = dest_x;
                    y_now = dest_y;
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 15440
#include <stdio.h>

static const int N = 200000;

int main(){
  int n,i,j, R[N];
  int maxv,minv;

  scanf("%d",&n);

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

    minv = R[0];
    maxv = R[1]-R[0];

    for(i=1;i<n;i++){
      if(R[i]-minv>maxv) maxv = R[i]-minv;
      if(R[i]<minv) minv = R[i];
    }


  printf("%d\n",maxv);

  return 0;
}

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

using namespace std;

int a[10000 + 1][730] = {0};

int main() {
    int N, M;
    while (cin >> N >> M && N + M) {
        for (int i = 0; i < 10001; i++) {
            for (int j = 0; j < 730; j++)
                a[i][j] = 0;
        }

        int r, q;
        cin >> r;
        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            a[m][t - 540] += (s == 1) ? 1 : -1;
        }
        
        for (int i = 1; i <= M; i++) {
            for (int j = 1; j <= 720; j++) {
                a[i][j] += a[i][j - 1];
            }
        }
        
        cin >> q;
        for (int i = 0; i < q; i++) {
            int ts, te, m;
            cin >> ts >> te >> m;
            ts -= 540; te -= 540;
            int sum = 0;
            for (int j = ts; j < te; j++) {
                if (a[m][j] > 0) ++sum;
            }
            cout << sum << endl;
        }
    }
}


Measured memory_bytes: 31572
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
 int ans; 
  ans =1000 - (n%1000);
  
  if (n%1000 == 0) {
    cout << 0 <<endl;
  }
 else {
 cout << ans << endl;
 }
  return 0;
}

Measured memory_bytes: 3592
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()

	var cards []int
	sc.Scan()
	inp := strings.Split(sc.Text(), " ")

	for _, c := range inp {
		cn, _ := strconv.Atoi(c)
		cards = append(cards, cn)
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	var alice int
	var bob int
	var aliceTurn bool = true

	for _, card := range cards {
		if aliceTurn {
			alice += card
			aliceTurn = false
		} else {
			bob += card
			aliceTurn = true
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 1788
use std::collections::BinaryHeap;

#[derive(Debug, Clone, Copy)]
struct Score {
    score: i64,
    node: usize,
}

impl Score {
    fn new(score: i64, node: usize) -> Self {
        Self { score, node }
    }
}

impl std::cmp::PartialEq for Score {
    fn eq(&self, other: &Self) -> bool {
        self.score == other.score
    }
}

impl std::cmp::Eq for Score {}

impl std::cmp::PartialOrd for Score {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl std::cmp::Ord for Score {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        match self.score.cmp(&other.score) {
            std::cmp::Ordering::Equal => std::cmp::Ordering::Equal,
            std::cmp::Ordering::Less => std::cmp::Ordering::Greater,
            std::cmp::Ordering::Greater => std::cmp::Ordering::Less,
        }
    }
}

fn solve(graph: Vec<Vec<(usize, i64)>>, start: usize) {
    let size = graph.len();
    let mut shortest: Vec<_> = vec![std::i64::MAX; size];
    shortest[start] = 0;
    let mut from: Vec<_> = vec![size + 1; size];
    let mut min_heap: BinaryHeap<Score> = BinaryHeap::from(vec![Score::new(0, start)]);
    from[start] = start;
    while let Some(Score { score, node }) = min_heap.pop() {
        for &(to, weight) in &graph[node] {
            let alternative_path = score + weight;
            if alternative_path < shortest[to] {
                shortest[to] = alternative_path;
                from[to] = node;
                min_heap.push(Score::new(alternative_path, to));
            }
        }
    }
    for s in shortest {
        if s == std::i64::MAX {
            println!("INF");
        } else {
            println!("{}", s);
        }
    }
}

use std::io::{BufRead, BufReader};
fn main() {
    let mut read = BufReader::new(std::io::stdin())
        .lines()
        .filter_map(|e| e.ok());
    let (v, _e, start) = {
        let line = read.next().unwrap();
        let line: Vec<&str> = line.split(' ').collect();
        let v: usize = line[0].parse().unwrap();
        let e: usize = line[1].parse().unwrap();
        let start: usize = line[2].parse().unwrap();
        (v, e, start)
    };
    let graph = {
        let mut graph: Vec<Vec<_>> = vec![vec![]; v]; // Adj list
        for edge in read {
            if edge.is_empty() {
                break;
            }
            let mut edge = edge.split(' ');
            let start: usize = edge.next().unwrap().parse().unwrap();
            let end: usize = edge.next().unwrap().parse().unwrap();
            let weight: i64 = edge.next().unwrap().parse().unwrap();
            graph[start].push((end, weight));
        }
        graph
    };
    solve(graph, start);
}



Measured memory_bytes: 25396
s = input()
if ((s[0] == '0' and s[1] != '0') or (s[0] == '1' and int(s[1]) <= 2)) and ((s[2] == '0' and s[3] != '0') or (s[2] == '1' and int(s[3]) <= 2)):
  print('AMBIGUOUS')
elif (s[0] == '0' and s[1] != '0') or (s[0] == '1' and int(s[1]) <= 2):
  print('MMYY')
elif (s[2] == '0' and s[3] != '0') or (s[2] == '1' and int(s[3]) <= 2):
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int temp;
            cin >> temp;
            d[i][j] = abs(a[i][j] - temp);
        }
    }
    int m = (h + w) * 80 + 2;
    vector<vector<vector<bool>>> dp(
        h, vector<vector<bool>>(w, vector<bool>(m, false)));
    dp[0][0][d[0][0]] = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < m; k++) {
                if (!dp[i][j][k]) continue;
                if (i + 1 < h) {
                    int diff_down = d[i + 1][j];
                    dp[i + 1][j][abs(k + diff_down)] =
                        dp[i + 1][j][abs(k + diff_down)] || dp[i][j][k];
                    dp[i + 1][j][abs(k - diff_down)] =
                        dp[i + 1][j][abs(k - diff_down)] || dp[i][j][k];
                }
                if (j + 1 < w) {
                    int diff_right = d[i][j + 1];
                    dp[i][j + 1][abs(k + diff_right)] =
                        dp[i][j + 1][abs(k + diff_right)] || dp[i][j][k];
                    dp[i][j + 1][abs(k - diff_right)] =
                        dp[i][j + 1][abs(k - diff_right)] || dp[i][j][k];
                }
            }
        }
    }
    for (int i = 0; i < m; i++) {
        if (dp[h - 1][w - 1][i]) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
 
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
vector<ll>q;

ll getAns(ll m){
	ll x=0;
	auto it=upper_bound(all(q),m)-q.begin()-1;
	return it;
}

void solve(){
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=0;i<=30;i++){
		q.pb(((i+1)*i)/2);
	}
	for(ll i=2;i*i<=n;i++){
		ll cnt=0;
		while(n%i==0){
			cnt++;
			n/=i;
		}
		ans+=getAns(cnt);
	}
	if(n>1)ans++;
	cout<<ans;
 
}
 
 
int main(){
	Blue;
	int test=1;
	//cin>>test;
	while(test--)
		solve();
	return 0;
}

Measured memory_bytes: 3628
//code by lynmisakura.wish to be accepted!
/*************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

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

ijt n,m;
ijt a[100010];
vector<ijt> G[100010];
vector<ijt> T[100010];
ijt tree;
int visited[100010];

void dfs(int x,int t) {
	visited[x] = 1;
	T[t].pb(a[x]);
	for (int i = 0; i < G[x].size(); i++)
	{
		if(!visited[G[x][i]])dfs(G[x][i],t);
	}
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < m; i++)
	{
		int x,y;cin >> x>>y;
		G[x].pb(y);
		G[y].pb(x);
	}
	for (int i = 0; i < n; i++)
	{
		if (!visited[i]) {
			dfs(i,tree++);
		}
	}
	ijt edge = 2 * (tree - 1);
	if (edge > n) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (n == 1 or tree == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < tree; i++)
	{
		sort(all(T[i]));
	}
	ijt ans = 0;
	vector<ijt> cost;
	for (int i = 0; i < tree; i++)
	{
		ans += T[i][0];
		for (int j = 0; j < T[i].size()-1; j++)
		{
			cost.pb(T[i][j+1]);
		}
	}
	sort(all(cost));
	for (int i = 0; i < edge - tree; i++)
	{
		ans += cost[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12148
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert (int k ) {
	Node *y = NIL; // yは親、xは現在地のノードを表す
	Node *x = root; // rootから探索する
	Node *z; // zは挿入したいノード

	z = ( Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while ( x != NIL) { //xがNILのときは、一番下の葉まで行った時
		y = x; //下に動く前に現在地をとして記憶
		if ( z->key < x->key ) {
			x = x->left;
		} else {
			x = x->right;
		}
	}

	z->parent = y;
	if ( y == NIL) {
		root = z;
	} else {
		if ( z->key < y->key ) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}	

void inorder(Node *u) {
	if ( u == NIL ) return;
	inorder(u->left);
	printf(" %d" , u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if ( u == NIL ) return;
	printf(" %d" , u->key);
	preorder(u->left);
	preorder(u->right);
}

int main () {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for ( i = 0; i < n; i++ ) {
		cin >> com;
		if ( com == "insert" ) {
			scanf("%d", &x); 
			insert(x);
		} else if ( com == "print" ) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int>data(N);
  for(int i=0;i<N;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  int b,e;
  b=data.at(0);
  e=data.at(N-1);
  int ans=1000000;
  for(int i=b;i<=e;i++){
    int tairyoku=0;
    for(int j=0;j<N;j++){
      tairyoku+=(data.at(j)-i)*(data.at(j)-i);
    }
    ans=min(tairyoku,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#else
#define debug(x) 
#endif
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
signed main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif 
    IOS
    int r; cin>>r;
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

bool isprime(int x)
{
    if(x == 2){
        return true;
    }
    if(x<2 || x%2 == 0){
        return false;
    }
    int i=3;
    while(i <= sqrt(x)){
        if(x%i == 0){
            return false;
        }
        i = i+2;
    }
    return true;
}

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

    int n;
    cin>>n;
    int a[n], cnt = 0;
    rep(i, n){
        cin>>a[i];
        if(isprime(a[i])){
            cnt += 1;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int N, M; cin >> N >> M;
  if(N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python3

import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def gcd(a, b):
    if a < b:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a


def main():
    A, B = [int(e) for e in inp().split()]

    G = gcd(A, B)

    ans = 1
    v = G
    p = 2
    while p * p <= v:
        if v % p == 0:
            ans += 1
            v //= p
            while v % p == 0:
                v //= p
        p += 1

    if v > 1:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38576
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HossamDoma
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            long q = in.nextLong();
            long h = in.nextLong();
            long s = in.nextLong();
            long d = in.nextLong();
            int n = in.nextInt();

            h = Math.min(h, 2 * q);
            s = Math.min(s, 2 * h);
            d = Math.min(d, 2 * s);

            out.println((n / 2) * d + (n % 2) * s);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}



Measured memory_bytes: 23252
import math
l=input().split()
W=int(l[0])
H=int(l[1])
x=int(l[2])
y=int(l[3])
r=int(l[4])
pi=math.pi
c_area=r**2*pi
square_area=W*H
if x>=-100 and y<=100 and W in range(0,101) and H in range(0,101) and r in range(1,101):
    if c_area>=square_area:
        print("No")
    elif x+r>W or y+r>H or x-r<0 or y-r<0:
        print("No")
    else:
        print("Yes")


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;

	cin >> n;

	ll now = 1;
	string s = "";

	REP(i, 32) {
		if (n % (abs(now) * 2) == 0) {
			s = "0" + s;
		}
		else {
			s = "1" + s;
			n -= now;
		}
		
		now *= -2;

		if (n == 0) {
			break;
		}
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int a, n, b;
		cin >> a>> b >> n;

		if(n/b==0)
			cout << (a*n)/b;
		else
			cout << ((a*(b-1))/b);
	}
	return 0;
}

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

int main() {
  string a,b;
  cin >> a >> b;

  string rst;
  if ((a == "H" && b == "H") || (a == "D" && b == "D")) rst = "H";
  else rst = "D";
  
  cout << rst << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    for (int i = 0; i != S.size(); ++i) {
        if (S[i] - '0' == (i & 1)) ++cnt;
    }
    cout << min(cnt, (int)S.size() - cnt) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	string a , b;
	cin >> a >> b;
	a += b;
	int x = stoi(a);
	int y = sqrt(x);
	if(y*y == x){
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{

    string s,t;
    cin>>s>>t;
    ll c=0;
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            c++;
    }
    cout<<c<<endl;




}


Measured memory_bytes: 3900
import scala.io.StdIn._
import scala.math._

/**
 * ABC112B
 */
object Main extends App {

  val in = readLine().split(" ").toSeq.map(_.toInt)
  val n = in(0)
  val tr = in(1)

  val c = (0 until n)
    .map(_ => readLine().split(" ").toSeq.map(_.toInt))
    .filter(_(1) <= tr)

  val ans = if (c.isEmpty) "TLE" else c.map(_(0)).min.toString

  println(ans)

}


    

Measured memory_bytes: 25536
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
using namespace std;


int main(){
  //cout << fixed << setprecision(12);
  lint A;
  double B;
  cin >> A >> B;
  B *= 100;
  B += 0.1;
  //cout << B << endl;
  lint C = B / 1;
  //cout << C << endl;
  
  lint ans = (A * C) / 100;
  cout << ans << endl;
}
  


Measured memory_bytes: 3724
package main

import (
	"fmt"
)

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

const (
	MOD = 1000000007
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	value int
	index int
	A, B  int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

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

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

func main() {
	var A, B, C, K int
	fmt.Scanf("%d %d %d %d\n", &A, &B, &C, &K)

	if A >= K {
		fmt.Println(K)
		return
	}
	sum := A
	K -= A
	if B >= K {
		fmt.Println(sum)
		return
	}
	K -= B
	fmt.Println(sum - K)
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


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

int main() {
	int n;
	double v[55];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (v[i] > v[j]) {
				int tmp = v[i];
				v[i] = v[j];
				v[j] = tmp;
			}
		}
	}
	
	while (n != 1) {
		v[0] = (v[0] + v[1]) / 2;
		
		for (int i = 2; i < n; i++) {
			v[i - 1] = v[i];
		}
		n--;
	}
	cout << v[0];
}


Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


mod=10**9+7
s=input()
n=len(s)
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(13):
        if s[i]=="?":
            for k in range(10):
                dp[i+1][(j*10+k)%13]+=dp[i][j]
                dp[i+1][(j*10+k)%13]%=mod
        else:
            dp[i+1][(j*10+int(s[i]))%13]+=dp[i][j]
            dp[i+1][(j*10+int(s[i]))%13]%=mod
print(dp[n][5]%mod)

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

int main(){
	int a, b;
	string op;
	while(cin >> a >> op >> b){
	if(op == "+") cout << a + b << endl;
	else if(op =="-") cout << a - b << endl;
	else if(op =="*") cout << a * b << endl;
	else if(op =="/") cout << a / b << endl;
	else if(op =="?") return 0;
	else return 0;
	}
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N = 100010;
int n, k, a[N];


int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 2e9+10;
    for (int i = 1; i+k-1 <= n; i++){
        if ((long long)a[i]*a[i+k-1] < 0)
            ans = min(ans, (int)abs(a[i])+(int)abs(a[i+k-1])+min((int)abs(a[i]), (int)abs(a[i+k-1])));
        else ans = min(ans, max((int)abs(a[i]), (int)abs(a[i+k-1])));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

bool wall[16*16];
int mv[] = {0, 1, -1, 16, -16};

int compress(int pa, int pb, int pc){
	return (pa)|(pb<<8)|(pc<<16);
}

int solve(int start, int goal){
	static bool visit[16*16*16*16*16*16];
	memset(visit, false, sizeof(visit));
	visit[start] = true;
	vector<int> state[2]; state[0].push_back(start);
	for(int res=1; ;res++){
		int cur = 1-res%2, next = res%2;
		state[next].clear();
		for(int i=0;i<state[cur].size();i++){
			int pa = state[cur][i]%256, pb = (state[cur][i]>>8)%256, pc = (state[cur][i]>>16);
			for(int a=0;a<5;a++){
				int npa = pa + mv[a];
				if(wall[npa]) continue;
				for(int b=0;b<(pb?5:1);b++){
					int npb = pb + mv[b];
					if(npb!=0){
						if(wall[npb]) continue;
						if(npa==npb) continue;
						if(npb==pa&&npa==pb) continue;
					}
					for(int c=0;c<(pc?5:1);c++){
						int npc = pc + mv[c];
						if(npc!=0){
							if(wall[npc]) continue;
							if(npc==npa||npc==npb) continue;
							if(npc==pa&&npa==pc) continue;
							if(npc==pb&&npb==pc) continue;
						}
						int ns = (npa)|(npb<<8)|(npc<<16);
						if(visit[ns]) continue;
						if(ns==goal) return res;
						visit[ns] = true;
						state[next].push_back(ns);						
					}
				}
			}
		}
	}
	return -1;
}

int main(){
	int w, h, n;
	string mp[16];
	while(cin >> w >> h >> n, w){
		getline(cin, mp[0]);
		for(int i=0;i<h;i++) getline(cin, mp[i]);
		memset(wall, false, sizeof(wall));
		int start = 0, goal = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(mp[i][j]=='#') wall[16*i+j] = true;
				if(islower(mp[i][j])) start |= (16*i+j) << (8*(mp[i][j]-'a'));
				if(isupper(mp[i][j])) goal  |= (16*i+j) << (8*(mp[i][j]-'A'));
			}
		}
		printf("%d\n", solve(start, goal));
	}
}

Measured memory_bytes: 0
n = int(input())
al = list(map(int, input().split()))

a_ind_val_l = []
for i, a in enumerate(al):
    a_ind_val_l.append((a,i))

a_ind_val_l.sort()
ans = []
for aiv in a_ind_val_l:
    ans.append(aiv[1]+1)

print(*ans)

Measured memory_bytes: 92772
#include <stdio.h>
#include <ctype.h>


int main(){
    
    char ch;
    
    while(1) {
        scanf("%c", &ch);
        
        if(islower(ch)){
            printf("%c",toupper(ch));
        }
        else{
            printf("%c",tolower(ch));
        }
        
        if(ch=='\n') break;
        
    }
    return(0);
}

Measured memory_bytes: 524
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v;
int N;
int l[210];
int main(){
    cin >> N;
    for(int i=0; i<2*N; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    };
    sort(v.begin(),v.end());
    int sum = 0;
    for(int i=0; i<2*N; i+=2) sum += v[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
import sys
sys.setrecursionlimit(10**6)
n=N()
p=L()
size=(n+1)**2+1
ans=[0]*size
for i in range(1,n+1):
    for j in range(1,n+1):
        k=i*(n+1)+j
        ans[k]=min(i-1,j-1,n-i,n-j)
c=[1]*size
di=[-1,1,n+1,-n-1]
def f(k,i):
    if k+i>=size:
        return
    if ans[k]+c[k]<ans[k+i]:
        ans[k+i]-=1
        q.append(k+i)
t=0
for i in p:
    y=i%n
    if y==0:
        y=n
    x=(i+n-1)//n
    k=x*(n+1)+y
    c[k]=0
    t+=ans[k]
    q=[k]
    while q:
        k=q.pop()
        f(k,1)
        f(k,-1)
        f(k,n+1)
        f(k,-n-1)
print(t)

Measured memory_bytes: 146012
n, x = map(int, input().split())
city = sorted(map(int, input().split()))
ans = abs(x - city[0])
if n > 1:
    dis = [city[i + 1] - city[i] for i in range(n - 1)]
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a%b)

    for i in range(n - 1):
        ans = gcd(ans, dis[i])
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
typedef pair<int,string> Q;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
//void swap(ll a,ll b){
//	ll d;
//	d=a;
//	a=b;
//	b=d;
//	return;
//}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
//    	cout<<b<<endl;
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int n;
int a[100005];
int x[100005]={};
ll ans=1;
int main() {
	cin>>n;
	x[0]=3;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n){
		ans=ans*(x[a[i]]-x[a[i]+1])%r197;
		x[a[i]+1]++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
class UnionFindVerSize():
  def __init__(self, N):
    self._parent = [n for n in range(0, N)]
    self._size = [1] * N
  def find_root(self, x):
    if self._parent[x] == x: 
      return x
    self._parent[x] = self.find_root(self._parent[x]) 
    return self._parent[x]
  def unite(self, x, y):
    gx = self.find_root(x)
    gy = self.find_root(y)
    if gx == gy:
      return
    if self._size[gx] < self._size[gy]:
      self._parent[gx] = gy
      self._size[gy] += self._size[gx]
    else:
      self._parent[gy] = gx
      self._size[gx] += self._size[gy]
  def get_size(self, x):
    return self._size[self.find_root(x)]
  def is_same_group(self, x, y):
    return self.find_root(x) == self.find_root(y)
n,m,k = map(int,input().split())
f = [0 for _ in range(n+1)]
uf = UnionFindVerSize(n+1)
for i in range(m):
  ai,bi = map(int,input().split())
  uf.unite(ai,bi)
  f[ai] += 1
  f[bi] += 1
l = [[] for _ in range(n+1)]
for i in range(k):
  ci,di = map(int,input().split())
  l[ci].append(di)
  l[di].append(ci)
for i in range(1,n+1):
  bf = 0
  for x in l[i]:
    if uf.is_same_group(i,x):
      bf += 1
  print(uf.get_size(i)-bf-f[i]-1,end=" ")
    

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

using namespace std;

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

  long long n;
  cin >> n;
  vector<long long> res(n+1, 0);
  res[0] = 2;
  res[1] = 1;
  for (int i = 2; i <= n; ++i) 
    res[i] = res[i-1]+res[i-2];
  cout << res[n] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    vector<ll> cnt(1e7+1);
    for (int i = 1; i <= 1e7; ++i) {
        for (int j = i; j <= 1e7; j += i) {
            cnt[j] += j;
        }
    }
    rep(i, 1e7) cnt[i+1] += cnt[i];

    int n;
    cin >> n;
    cout << cnt[n] << endl;
}


Measured memory_bytes: 81252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define precision(x) fixed << setprecision(x)
#define all(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(all(x))
#define SUM(x) accumulate(all(x),0LL)
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000

int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double PI = acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    int n, i=0, x;
    cin >> n;
    while(++i <= n){
        x = i;
        if(x % 3 == 0){
            cout << " " << i;
            continue;
        }
        while(x){
            if(x % 10 == 3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3132