akhauriyash/Code-Regression huggingface dataset:
class UnionFind
    attr_reader :set_size
    attr_reader :ans
    def initialize(n)
        @par = Array.new(n)
        n.times{ |i| @par[i] = i }
        @rank = Array.new(n, 0)
        @set_size = Array.new(n, 1)

        @ans = n*(n-1)/2
    end

    def find(x)
        if @par[x] == x
            x
        else
            @par[x] = find(@par[x])
        end
    end

    def unite(x,y)
        x = find(x)
        y = find(y)
        return if x == y

        @ans -= @set_size[y] * @set_size[x]

        if @rank[x] < @rank[y]
            @par[x] = y
            @set_size[y] += @set_size[x]
        else
            @par[y] = x
            @set_size[x] += @set_size[y]
            @rank[x] += 1 if @rank[x] == @rank[y]
        end
    end

    def same?(x, y)
        find(x) == find(y)
    end
end


N, M = gets.split.map(&:to_i)
as, bs = M.times.map{gets.split.map(&:to_i)}.transpose

uf = UnionFind.new(N)
ans = []
(M-1).downto(0) do |i|
    ans[i] = uf.ans
    uf.unite(as[i]-1, bs[i]-1)
end
puts ans

Measured memory_bytes: 16764
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N;
	vl A(N);
	vpll odd(100000);
	vpll even(100000);
	for (i = 0; i < 100000; i++) {
		odd[i] = make_pair(0, i);
		even[i] = make_pair(0, i);
	}
	for (i = 0; i < N; i++) {
		cin >> A[i];
		if (i % 2 == 0) odd[A[i] - 1].first++;
		else even[A[i] - 1].first++;
	}
	sort(odd.begin(), odd.end());
	reverse(odd.begin(), odd.end());
	sort(even.begin(), even.end());
	reverse(even.begin(), even.end());
	if (odd[0].second != even[0].second) cout << N - odd[0].first - even[0].first;
	else if (N == 2) cout << 1;
	else if (odd[1].first > even[1].first) cout << N - odd[1].first - even[0].first;
	else cout << N - odd[0].first - even[1].first;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
double dp(int i,int cnt);
int n;
double p[3009];
double memo[3009][3009];

int main(){
  cin>>n;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      memo[i][j]=-1;
    }
  }
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  printf("%.10f\n",dp(0,0));
}

double dp(int i,int cnt){
  double rec=0;
  if(memo[i][cnt]!=-1)return memo[i][cnt];
  if(i==n){
    if(cnt>(n-cnt)){
      return 1;
    }
    else{
      return 0;
    }
  }
  rec+=dp(i+1,cnt)*(1-p[i]);
  rec+=dp(i+1,cnt+1)*p[i];
  return memo[i][cnt]=rec;
}


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

int main()
{
  string s;
  cin >> s;
  bool first_three_eq = s.at(0) == s.at(1) && s.at(1) == s.at(2);
  bool last_three_eq = s.at(1) == s.at(2) && s.at(2) == s.at(3);
  if(first_three_eq || last_three_eq) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		a[i] -= i + 1
	}
	sort.Ints(a)
	b := a[n/2]
	ans := 0
	for _, e := range a {
		ans += abs(e - b)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4736
# coding: utf-8
# Problem B: ??£????¶?????????????
require 'scanf'

def find_chunks(board)
  chunks = []
  
  board.each_with_index do |row, i|
    start = nil
    cnt = 1

    row.each_with_index do |p, j|
      if p && p == row[j + 1]
        start ||= j
        cnt += 1
      else
        if cnt >= 3
          chunks << {point: row[start], row: i, start: start, cnt: cnt}
        end

        cnt = 1
        start = nil
        
      end
    end
  end

  chunks
end

def calc_points(chunks)
  chunks
    .map {|c| c[:point] * c[:cnt] }
    .inject(0, :+)
end

def eliminate(board, chunks)
  chunks.each do |chunk|
    row = board[chunk[:row]]
    row.fill(nil, chunk[:start], chunk[:cnt])
  end
end

def fall_blocks(board)
  while true
    cont = false

    (0..board.size - 1).reverse_each do |i|
      board[i].each_with_index do |p, j|
        break if i == 0
        ap = board[i - 1][j]

        if !p && ap
          #swap
          board[i][j] = ap
          board[i - 1][j] = p

          cont = true
        end
      end
    end

    return unless cont

  end
end

require 'pp'
while true
  h = gets.to_i
  break if h == 0
  board = []
  
  h.times do
    board << gets.scanf('%d %d %d %d %d')
  end

  points = 0

  while true
    chunks = find_chunks(board)
    break if chunks.size == 0

    points += calc_points(chunks)
    eliminate(board, chunks)
    fall_blocks(board)
  end

  puts points
end

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

int main(){
    string n,m;
    cin>>n>>m;
    if(n.size()<m.size()) return 0;
    for(int i=0;i<n.size()-m.size()+1;i++){
        string x=n.substr(i,m.size());
        if(m==x){
            cout<<i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3224
#include"bits/stdc++.h"
 
using namespace std;
 
#define MAX 40004
 
int n;
 
 
long double A[MAX];
long double B[MAX];
 
vector<pair<double, double> > v;
 
vector<pair<long double, long double > > mp;
 
struct BIT {
	vector<int> bit;
	void resize(int N) {
		bit.assign(N, 0);
	}
	void add(int i, int j) {
		i++;
		while (i < bit.size()) {
			bit[i] += j;
			i += i&-i;
		}
	}
	int sum(int i) {
		int r = 0;
		i++;
		while (i) {
			r += bit[i];
			i -= i&-i;
		}
		return r;
	}
	int rng(int lef, int rig) {
		int F = sum(rig);
		if (lef) {
			F -= sum(lef - 1);
		}
		return F;
	}
};
BIT b;
 
map<long double, int> mpp;
int ord[MAX];
 
int cnt_lef(long double X) {
	b.resize(n + 1);
	mp.clear();
	for (int i = 0; i < n; i++) {
		mp.push_back({ A[i] * X + B[i],ord[i] } );
	}
	sort(mp.begin(), mp.end());
	int same = 0;
	int rig = 0;
	double pr = -114;
	int conc = 0;
	for (auto it = mp.rbegin(); it != mp.rend(); it++) {
		if ((*it).first == pr) {
			conc++;
		}
		else {
			conc = 1;
			pr = (*it).first;
		}
		same += conc-1;
		rig += b.sum((*it).second - 1);
		b.add((*it).second, 1);
	}
	int lef = n*(n - 1) / 2 - same - rig;
	return rig - lef;
}
 
double solve() {
	mpp.clear();
	for (int i = 0; i < n; i++) {
		mpp[A[i]] = 0;
	}
	int cc = 0;
	for (auto it = mpp.begin(); it != mpp.end(); it++) {
		(*it).second = cc;
		cc++;
	}
	for (int i = 0; i < n; i++) {
		ord[i] = mpp[A[i]];
	}
	long double mint = -199999999;
	long double maxt = 199999999;
	long double EP = 1e-9;
	while (mint + EP < maxt) {
		long double mid = (mint + maxt) / (long double)2.0;
		int flag = cnt_lef(mid);
		if (flag <= 0) {
			maxt = mid;
		}
		else {
			mint = mid;
		}
	}
	return mint;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		A[i] = (long double)(a) / (long double)(b);
		B[i] = -(long double)(c) / (long double)(b);
	}
	double X = solve();
	for (int i = 0; i < n; i++) {
		pair<long double, long double> p = make_pair(0, B[i]);
		pair<long double, long double> p2 = make_pair(1, A[i] + B[i]);
		swap(p.first, p.second);
		swap(p2.first, p2.second);
		p.first *= -1.0;
		p2.first *= -1.0;
		A[i] = (p2.second - p.second) / (p2.first - p.first);
		B[i] = p.second - A[i] * p.first;
	}
	double Y = solve();
	printf("%.16f %.16f\n", X, Y);
	return 0;
}

Measured memory_bytes: 8304
while True:
    n = int(input())
    if n == 0:
        break
    To_lis = [0,0,0,0,0,0,0]
    for i in range(n):
        tosi = int(input())
        if tosi < 10:
            To_lis[0] += 1
        elif tosi < 20:
            To_lis[1] += 1
        elif tosi < 30:
            To_lis[2] += 1
        elif tosi < 40:
            To_lis[3] += 1
        elif tosi < 50:
            To_lis[4] += 1
        elif tosi < 60:
            To_lis[5] += 1
        else:
            To_lis[6] += 1
    for k in range(len(To_lis)):
        print(To_lis[k])

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

int main(){
  /* code */
  int seconds;
  cin >> seconds;
  int t, m, s;
  t = seconds / 3600;
  m = (seconds % 3600) / 60;
  s = (seconds % 60);
  cout << t << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 3104
# coding:utf-8

import sys
import heapq
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()

    ss = [ord(c) for c in s]
    abc = [ord(c) for c in 'abcdefghijklmnopqrstuvwxyz']
    if len(s) < 26:
        sss = set(ss)
        for c in abc:
            if c not in sss:
                return s + chr(c)
    hq = []
    prev = ss[-1]
    for i in range(len(s))[::-1]:
        c = ss[i]
        if c >= prev:
            heapq.heappush(hq, c)
        else:
            while hq and hq[0] < c:
                heapq.heappop(hq)
            return s[:i] + chr(hq[0])
        prev = c

    return -1


print(main())


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

int main()
{
    int h,w;
    cin >> h >> w;
    queue<string> v;
    string current;
    for(int i=0;i<h;i++){
        cin >> current;
        v.push(current);
    }
    while(!v.empty()){
        cout << v.front() << endl;
        cout << v.front() << endl;
        v.pop();
    }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  long long n,a=0;
  cin>>n;
  int d[n][n];
  r(i,n)r(j,n){cin>>d[i][j];
    if(j<i)a+=min(d[i][j],d[j][i]);
  }
  cout<<a<<endl;
}

Measured memory_bytes: 3124
#include<cstdio>
using namespace std;
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	
	if(x%y!=0)
	{
		printf("%d\n",x);
		return 0;
	}
	else
	{
		printf("-1\n");
		return 0;
	}
	return 0;
} 

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

int main() {
    int x, y;
    for(int i=0;i<3000;i++){
        cin >> x >> y;
        if(x == 0 && y == 0)break;
        else cout << min(x, y) << " " << max(x, y) << endl;
    }
}


Measured memory_bytes: 3084
#include<iostream>
#define MAX 101
using namespace std;
 
int main()
{
  int n,m=0;
  int c[MAX]={};
 
  while(cin>>n)c[n]++;
  for(int i=0;i<MAX;i++)m=max(m,c[i]);
  for(int i=1;i<MAX;i++)if(m==c[i])cout<<i<<endl;
   
  return 0;
}


Measured memory_bytes: 3096
#define fariha                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main()
{
    fariha;
    int n, m;

    cin >> n >> m;

    if (n == m)
        cout << "Yes";
    else
        cout << "No";
}

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

int main(){
  int a[10];
  int tmp;
  int n = 0;

  while(n<10){
    cin >> a[n];
    n++;
  }

  int i,j;

  //降順ソート
  for(i = 0;i < 10;i++){
    for(j = i+1;j < 10;j++){
      if(a[i] < a[j]){
	tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
      }
    }
  }

  //結果の表示
  for(i = 0;i < 3;i++){
    cout << a[i] << endl;
  }
    return 0;
}



Measured memory_bytes: 3080
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String str=sc.next();
    char[] c=str.toCharArray();

    for(int i=0;c.length>i;i++){
      if(c[i]=='P' || c[i]=='D') continue;
      else c[i]='D';
    }
    /*int countD=0;
    int countPD=0;
    for(int i=0;c.length>i;i++){
      if(c[i]=='D') countD++;
      else continue;
    }
    for(int i=0;c.length>i;i++){
      int j=1;
      if(c[i]=='P' && c[j]=='D') countPD++;
      else continue;
      j++;
    }*/
    System.out.println(c);
  }
}

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

using namespace std;

int main()
{
    double h;
    vector<double> a;
    while (cin >> h) {
        a.push_back(h);
    }
    cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;
    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

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

ll lcm(ll a, ll b)
{
   return a  / gcd(a, b) * b;
}
int main(){
    ll a,b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

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

void solve(std::string S) {
    for (int i = 0; i < S.length(); i++) {
        cout << 'x';
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
using namespace std;
int main() {
    int n, m, kotae;


    cin >> n >> m;
    array<int, 1000100> ans;
    array<int, 1000100> v;
    kotae = n;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        v.at(i) = d;
    }

    for (int j = 0; j < m; j++) {
        int a1, a2;
        cin >> a1 >> a2;
        if (v.at(a1 - 1) > v.at(a2 - 1)) {
            ans.at(a2 - 1) = 1;
        }else  if (v.at(a1 - 1) < v.at(a2 - 1)) {
            ans.at(a1 - 1) = 1;
        }else {
          ans.at(a2 - 1) = 1;
          ans.at(a1 - 1) = 1;
        }
    }

    for (int j = 0; j < n; j++) {
        if (ans.at(j) == 1)kotae--;
    }
    cout << kotae;

}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define MP(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

unordered_map<int, int> m;

int main()
{
	int N;
	cin >> N;
	int res = 0;
	rep(i, N) {
		CIN(int, a);
		if (m.find(a) != m.end()) {
			m[a] = 1 - m[a];
			if (m[a]) res++;
			else res--;
		} else {
			m.insert(MP(a, 1));
			res++;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 4388
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		double[] A = Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();

		double sum = A.Sum(x => 1.0 / x);
		Console.WriteLine($"{1.0/sum:F12}");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 13396
n = gets.to_i
ary = gets.split(' ').map(&:to_i)

ary = ary.sort.reverse

score = 0
ary.each_with_index{|a, i|
  if i % 2 == 0 then
    score += a
  else
    score -= a
  end
}

puts score.to_s


Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int n,cnt,kin;
int a[maxn],st[maxn];
int read(){
    int res = 0;
    int flag = 0;
    char ch;
    if ((ch = getchar()) == '-'){
        flag = 1;
    }
    else if(ch >= '0' && ch <= '9'){
        res = ch - '0';
    }
    while ((ch = getchar()) >= '0' && ch <= '9'){
        res = res * 10 + (ch - '0');
    }
    return flag ? -res : res;
}
void init(){
    scanf("%d",&n);
    for(int i = 0 ; i < n ; i++)
        a[i] = read();
    sort(a,a+n);
    cnt = 0;
    kin = 1;
    for(int i = 1 ; i < n ; i++){
        if(a[i] == a[i-1])
            st[++cnt] = a[i];
        else    kin++;
    }
    int ans  =0;
    if(cnt %2 == 0) ans = kin;
    else    ans = kin-1;
    printf("%d\n",ans);
}

int main(){
    init();
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define S(x, y) (x>=0 && x<h && y>=0 && y<w ? s[y][x] : '.')

int main(void) {
	char **s;
	int h, w, i, j;
	int flag = 0;
	
	scanf("%d %d", &h, &w);
	s = malloc(sizeof(char) * (h));
	
	for (i = 0; i < h; i++) {
		s[i] = malloc(sizeof(char) * (w));
		for (j = 0; j < w; j++) {
			scanf(" %c", &s[i][j]);
			if (S(j, i-1) == '#') {
				if (S(j-1, i-1) != '#' && S(j,i-2) != '#' &&
					S(j+1, i-1) != '#' && S(j, i) != '#') {
					flag = 1;
				}
			}
		}
	}
	
	printf(flag ? "No" : "Yes");
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,m,ans,a[maxn],cnt[maxn],sum[maxn];
void judge(int x,int v)
{
	if(x>cnt[x])
	{
		sum[x-cnt[x]]+=v;
		if(v==1 && sum[x-cnt[x]]==1)
		{
			ans--;
		}
		if(v==-1 && sum[x-cnt[x]]==0)
		{
			ans++;
		}
	}
}
int main()
{
	cin>>n>>m;
	ans=n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		judge(a[i],1);
		cnt[a[i]]++;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		cnt[a[x]]--;
		judge(a[x],-1);
		judge(y,1);
		cnt[y]++;
		a[x]=y;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

#define  kak 1000000000000;



int main(){
    ll N;
    ll C;
    ll K;
    cin >> N;
    cin >> C;
    cin >> K;
    vector<long long> T(N);
    ll n = 0;
    ll t = 0;
    ll count = 0;

    for (int i = 0; i < N; ++i) {
        cin >> T[i];
    }
    sort(T.begin(),T.end());


    for (int i = 0; i < N; ++i) {
        if(T[i]-T[i-n] <= K ){
            n ++;
            if(n == C){
                n = 0;
                count ++;
            }
        }else {
            count ++ ;
            n = 1;
        }
    }

    if(n!=0) count++;
    cout << count;




    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n,suff=0;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++){
        cin>>a[i];
        suff^=a[i];
  }
   ll ori=suff;
  ll xorr=0;
  for(int i=0;i<n;i++){
   a[i]=suff^a[i];
   cout<<a[i]<<" ";

  }
  cout<<endl;
}


Measured memory_bytes: 5124
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

template<class T> class LazySegT {

   int N;
   vector<T> node, lazy;

   public:
      LazySegT(vector<T> v) {
         int SIZE = v.size();
         N = 1;
         while (N < SIZE) N *= 2;
         node.resize(2 * N - 1);
         lazy.resize(2 * N - 1, 0);

         // lowest level
         for (int i = 0; i < SIZE; i++) 
            node[i + N - 1] = v[i];
         // others
         for (int i = N - 2; i >= 0; i--) 
            node[i] = node[2 * i + 1] + node[2 * i + 2];
      }
     
      void eval(int k, int l, int r) {
         if (lazy[k] != 0) {
            node[k] += lazy[k];

            if (r - l > 1) {
               lazy[2 * k + 1] += lazy[k] / 2;
               lazy[2 * k + 2] += lazy[k] / 2;
            }

            lazy[k] = 0;
         }
      }
      
      void add(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
         if (r < 0) r = N;

         eval(k, l, r);
         if (b <= l || r <= a) return;
         if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
         } else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
         }
      }

      T getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
         if (r < 0) r = N;
         if (b <= l || r <= a) return 0;

         eval(k, l, r);
         if (a <= l && r <= b) return node[k];
         T vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
         T vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
         return vl + vr;
      }
};

int main() {
   int n, Q;
   cin >> n >> Q;
   LazySegT<ll> segt( vector<ll>(n, 0) );
   int t, a, b, x;
   for (int q = 0; q < Q; q++) {
      cin >> t;
      if (t == 0) {
         cin >> a >> b >> x;
         a--;
         b--;
         segt.add(a, b + 1, x);
      } else {
         cin >> a >> b;
         a--;
         b--;
         cout << segt.getsum(a, b + 1) << endl;
      }
   }
   return 0;
}


Measured memory_bytes: 7576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll pos,len;
char s[10010];

ll f(){
	if(s[pos]!='['){
		ll temp=atoi(s+pos);
		pos=strchr(s+pos,']')-s+1;
		return temp/2+1;
	}
	ll a[4000]={},acnt=0;
	while(pos<len&&s[pos]!=']'){
		pos++;
		a[acnt++]=f();
	}
	pos++;
	sortup(a,acnt);
	ll ans=0;
	rep(i,0,acnt/2+1)ans+=a[i];
	return ans;
}

int main(){
	ll n;
	scanf("%lld",&n);
	while(n--){
		scanf(" %s",s);
		len=strlen(s);
		pos=0;
		printf("%lld\n",f());
	}
}


Measured memory_bytes: 2132
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    n = i_input()
    l = [list(s_input()) for _ in range(n)]

    ans = []
    for i in l[0]:
        trial = 1
        for k in range(n-1):
            if i  not in l[k+1]:
                trial = 0
        if trial == 1:
            ans.append(i)
            for r in range(n-1):
                l[r+1].remove(i)
    ans.sort()
    print("".join(ans))



if __name__=="__main__":
    main()


Measured memory_bytes: 74676
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n ):
            if l[k] <l[i] + l[j] and l[k] != l[i] and l[i] != l[j] and l[j] != l[k]:
                ans += 1
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n, ans = 0;
  cin >> n;
  vector<pair<ll, ll> > a(n);
  rep(i, 0, n) {
    a[i].first = i+1;
    cin >> a[i].second;
    if(a[i].first > a[i].second) swap(a[i].first, a[i].second);
  }
  sort(all(a));
  ll f, s, cnt = 1;
  tie(f, s) = a[0];
  rep(i, 1, n) {
    bool boo = (a[i].first==f and a[i].second==s);
    if(boo) cnt++;
    if(not(boo) or i==n-1) {
      ans += (cnt*(cnt-1))/2;
      cnt = 1;
      f = a[i].first;
      s = a[i].second;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1792
#ユークリッドの互除法
def gcd(x,y):
    while y != 0:
        x, y = y, x%y
#        print(x,y)
    return(x)

k = int(input())

ans_l1 = []
ans_l2 = []
ans = 0
for a in range(1,k+1):
    for b in range(1,a+1):
        for c in range(1,k+1):
            if a == b:
                ans += gcd(gcd(a,b),c)
            else:
                ans += 2*gcd(gcd(a,b),c)

print(ans)

Measured memory_bytes: 68592
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+')
    {
        cout << a + b << endl;
    }
    else
        cout << a - b << endl;

    return 0;
}

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

class Cube{
public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1, 2, 4, 3);}
    void roll_y(){roll(0, 2, 5, 3);}
    void roll_x(){roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    }
};

int getRight(Cube c1, int f1, int f2){
    for (int i = 0; i < 6; i++){
        for (int j = 0; j < 4; j++){
            if(c1.f[0] == f1 && c1.f[1] == f2) return c1.f[2];
            c1.roll_z();
        }
        if(i % 2 == 0) c1.roll_y();
        else c1.roll_x();
    }
    return -1;
}


int main(){
    Cube c;
    int f1, f2;

    for(int i = 0; i < 6; i++) cin >> c.f[i];
    
    int q;
    cin >> q;

    for(int i = 0; i < q; i++){
        cin >> f1 >> f2;
        cout << getRight(c, f1, f2) << endl;
   }

}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX 100005
char s[MX];
int N,L[MX],R[MX],S[MX];
int main(void){
    scanf("%s",s),N=strlen(s);
    F(N)R[i]=s[i]=='R'?i:R[i-1];
    for(int i=N-1;~i;--i)L[i]=s[i]=='L'?i:L[i+1];
    F(N)if(s[i]^'L'){
        int I=L[i];
        I-=(I-i)&1;
        ++S[I];
    }else {
        int I=R[i];
        I+=(i-I)&1;
        ++S[I];
    }
    F(N)printf("%d%c",S[i],i+1==N?10:32);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
int ans[100010]={};

int main()
{

queue<ll> q;
ll n;
cin >> n;
vector<pair<ll,ll> > G[n];
rep(i,n+5){
    ans[i]=-1;
}
ans[0]=0;
rep(i, n-1)
{
    ll a,b,c;
    cin >> a>>b>>c;
    G[a-1].push_back(pair<ll,ll>(b-1, c));
    G[b-1].push_back(pair<ll,ll>(a-1, c));
}
q.push(0);
while(!q.empty()){
    ll aa=q.front();
    //cout << "aa"<<aa+1 << endl;
    q.pop();
    rep(i,G[aa].size()){
        if(ans[G[aa][i].first]>=0)continue;
        q.push(G[aa][i].first);
        if(G[aa][i].second%2==0)ans[G[aa][i].first]=ans[aa];
        else ans[G[aa][i].first]=(ans[aa]+1)%2;
    }
}
rep(i,n){
    cout << ans[i] << endl;
}

return 0;
}

Measured memory_bytes: 8320
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, k: usize);

    // N頂点の連結グラフには、少なくともN-1の辺がある
    // 全頂点の組み:N(N-1)/2
    // 辺で繋がれた頂点の組み:N-1
    // 最短距離が2の頂点の組み:N(N-1)/2 - (N-1) = (N-1)(N-2)/2 以下になる
    // -> K > N(N-1)/2 の時、構築できない
    // else 最短距離が2の頂点の組みがK個になるまで、スターグラフの任意の頂点を繋げればいい

    // 下限 完全グラフ(全ての頂点同士が辺で繋がっている)の時:0
    // 上限 スターグラフ(N-1個の頂点が真ん中の頂点とだけ辺で繋がっている)の時:(N-1)(N-2)/2

    let lim_node = (n - 1) * (n - 2) / 2;
    if k > lim_node {
        println!("-1");
    } else {
        // スターグラフ構築
        let mut graph = vec![];
        for i in 0..n - 1 {
            graph.push((i + 1, n));
        }

        // 新たに繋げる辺の候補を列挙
        let mut edge = vec![];
        for v in 0..n - 1 {
            for u in 0..v {
                edge.push((v + 1, u + 1));
            }
        }

        // 繋げる
        let add_num = lim_node - k;
        for i in 0..add_num {
            graph.push(edge[i]);
        }

        println!("{}", graph.len());
        for &(v, u) in graph.iter() {
            println!("{} {}", v, u);
        }
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[6];
int main(){
  rd(S);
  sort(S,S+4);
  if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190630-1

// --- original code ---
// char S[6];
// {
//   rd(S);
//   sort(S,S+4);
//   wt(if[S[0]==S[1]!=S[2]==S[3], "Yes", "No"]);
// }


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

int main() {
  int n;
  cin >> n;
  int indexes[n];
  rep(i, n) {
    indexes[i] = i + 1;
  }

  vector<int> permutations;
  int cur = 0;
  do {
    int built = 0;
    rep(i, n) {
      built += indexes[i] * (int)pow(10, i);
    }
    permutations.push_back(built);
    cur++;
  } while (std::next_permutation(indexes, indexes + n));

  sort(permutations.begin(), permutations.end());

  int p = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    p += tmp * (int)pow(10, n-i-1);
  }

  int q = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    q += tmp * (int)pow(10, n-i-1);
  }

  int a = lower_bound(permutations.begin(), permutations.end(), p) - permutations.begin();
  int b = lower_bound(permutations.begin(), permutations.end(), q) - permutations.begin();

  cout << abs((a+1) - (b+1)) << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
#input = sys.stdin.buffer.readline
from collections import deque
 
def main():
    N = int(input())
    edge = [list(str(input())) for _ in range(N)]

    dist = [-1 for _ in range(N)]
    col = [0 for _ in range(N)]
    dist[0],col[0] = 0,1
    q = deque([(0,1)])
    D = 0
    while q:
        now,nc = q.popleft()
        for i in range(N):
            if edge[now][i] == "1":
                fol = i
                if col[fol] == 0:
                    col[fol] = -1*nc
                    q.append((fol,-1*nc))
                elif col[fol] == nc:
                    print(-1)
                    exit()

    def getmax(x):
        dist = [-1 for _ in range(N)]
        dist[x] = 1
        q = deque([x])
        while q:
            now = q.popleft()
            for i in range(N):
                if edge[now][i] == "1":
                    fol = i
                    if dist[fol] == -1:
                        dist[fol] = dist[now]+1
                        q.append(fol)
        return max(dist)
    
    print(max(getmax(i) for i in range(N)))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

class Main {
	
	public static BigDecimal INTEREST_RATE = new BigDecimal("0.05");
	
	public static void main(String... args) {
		Scanner scanner = null;
		try {
			scanner = new Scanner(System.in);
			int n = scanner.nextInt();
			BigDecimal baseDebt = new BigDecimal(100000);
			BigDecimal debt = calc(baseDebt, n);
			System.out.println(debt.intValue());
		} finally {
			scanner.close();
		}
	}
	
	public static BigDecimal calc(BigDecimal debt, int n) {
		if (n <= 0) {
			return debt;
		}
		BigDecimal interest = debt.multiply(INTEREST_RATE);
		BigDecimal afterDebt = debt.add(interest).setScale(-3, RoundingMode.UP);
		return calc(afterDebt, --n);
	}
}

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

const int N = 1e5 + 5;

int n;
int a[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	int res = 0, cnt = 0;
	for (int i = 1; i <= n + 1; ++i) {
		if (a[i] != a[i - 1]) {
			res += (cnt / 2);
			cnt = 0;
		}
		cnt++;
	}
	cout << res << '\n';
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())

L = sorted([A, B, C])

cnt1 = L[2] - L[1]
diff = L[2] - (L[0] + cnt1)

if diff % 2 == 0:
  cnt2 = (L[2]-(L[0]+cnt1)) // 2
  print(cnt1 + cnt2)
else:
  cnt2 = (L[2] + 1 - (L[0] + cnt1)) // 2
  print(cnt1+cnt2+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
using namespace std;

int main()
{
	ll int n,m;
	cin>>n>>m;
	vector< ll int> v[n+1];
	ll int a[n];
	ll int i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	while(m--)
	{
		ll int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
		
		
	}
	ll int j,f,c=0;
	for(i=1;i<=n;i++)
	{
		f=0;
		
		for(j=0;j<v[i].size();j++)
		{
			if (a[i-1]<=a[v[i][j]-1])
			{
				f=1;
				break;
			}
		}
		if (f==0)
		c++;
		
		
	}
	cout<<c<<endl;
	
	
} 




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

int main() {
    int64_t x;
    cin >> x;

    int64_t ans = 0;
    ans += (x/500)*1000;
    x -= (x/500)*500;
    ans += (x/5)*5;

    cout << ans;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
int m[555][555];
int d[555][555];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < num; j++)
		{
			d[i + 1][j + 1] = min(min(i, j), min(num - 1 - i, num - 1 - j)) + 1;
			m[i + 1][j + 1] = 1;
		}
	}
	int ans = 0;
	for (int p = 0; p < num*num; p++)
	{
		int z;
		scanf("%d", &z);
		z--;
		int x = z / num, y = z%num;
		x++, y++;
		m[x][y] = 0;
		deque<pii>que;
		que.push_back(make_pair(x, y));
		for (;;)
		{
			if (que.empty())break;
			pii z = que.front();
			que.pop_front();
			int mini = 1000000;
			for (int i = 0; i < 4; i++)mini = min(mini, d[z.first + dx[i]][z.second + dy[i]]);
			if (m[z.first][z.second])mini++;
			if (mini >= d[z.first][z.second])continue;
			d[z.first][z.second] = mini;
			for (int i = 0; i < 4; i++)
			{
				if (m[z.first + dx[i]][z.second + dy[i]])que.push_back(make_pair(z.first + dx[i], z.second + dy[i]));
				else que.push_front(make_pair(z.first + dx[i], z.second + dy[i]));
			}
		}
		ans += d[x][y];
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 9064
// The very basic /////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ALL_H 1

// Print elements of containers using << operator /////////////////////////////
// pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  return s << "(" << p.first << ", " << p.second << ")";}
// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  for (auto &elem : v) {
    s << elem;
    if (&elem != &v.back()) s << " ";
  }
  return s;
}
// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  for (auto &elem : vv) {
    s << elem;
    if (&elem != &vv.back()) s << endl;
  }
  return s;
}
// map
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{" << endl;
  for (auto &elem: m) {
    s << " " << elem.first << " : " << elem.second << endl;
  }
  s << "}";
  return s;
}
//set
template<typename T> ostream& operator<<(ostream& s, const set<T>& m) {
  s << "{ ";
  for (auto &elem: m) {
    s << elem << " ";
  }
  s << "}";
  return s;
}

// Convenient macros //////////////////////////////////////////////////////////

// types
#define ll long long
#define ld long double
#define int ll
#define Pi pair<int, int>
#define Graph vector<vector<int>>
#define WeightGraph vector<vector<Pi>>

// other
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

#define MOD 1000000007
#define INF LLONG_MAX/100

// update max or min //////////////////////////////////////////////////////////

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// gcd
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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


// Debug it by D(x) ///////////////////////////////////////////////////////////
#define DEBUG 0
#if DEBUG
#define D(x) x
#else
#define D(x)
#endif

///////////////////////////////////////////////////////////////////////////////
//                             Start Coding Here                             //
///////////////////////////////////////////////////////////////////////////////

signed main() {
  int N, M; cin >> N >> M;
  string A = "", B = "";
  rep(i, N) A += to_string(M);
  rep(i, M) B += to_string(N);
  D(cout << A << " " << B << endl);
  if (A < B) {
    cout << A << endl;
  } else {
    cout << B << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);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 INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
  if ( !v.empty() ) {
    out << '[';
    copy (v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.precision(16);
    
    long long n;
    cin >> n;

    int ans = to_string(n).length();
    int limit = sqrt(n) + 1;
    for(int i = 1; i < limit; i++) {
        if(n % i == 0) {
            ans = min(ans, (int)max(to_string(i).length(), to_string(n/i).length())); 
        }
    }
#if DEBUG
	cout << "** RESULT **" << endl; // debug
#endif
    cout << ans << endl;
	
	return 0;
}


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

long long dp[101][100001];
int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  for( int i=1, wi, vi; i<=n; ++i )
  {
    scanf("%d%d", &wi, &vi);
    for( int j=1; j<=w; ++j )
      if( wi <= j )
        dp[i][j] = max( dp[i-1][j], dp[i-1][j-wi] + vi );
      else
        dp[i][j] = dp[i-1][j];
  }
  printf("%lld\n", dp[n][w] );
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    VI w(n); VIin(w);
    int s1 = 0 , s2 = 0;
    rep(i,n) s2 += w[i];
    int ans = INF;
    rep(i,n-1){
        s1 += w[i];
        s2 -= w[i];
        ans = min(ans,abs(s1 - s2));
    }
    ANS;
    
    return 0;
}

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

int main()
{
	int x, y;
	for (int i = 1; i > 0;) {
		cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		}

		else {
			if (x > y) {
				swap(x, y);
			}

			cout << x << ' ' << y << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 2964