akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll moddividing(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<ll> A_copy(N);
    rep(i,N){
        A_copy[i] = A[i];
    }
    vector<vector<ll> > prime_count(N, vector<ll>(1001));
    rep(i,N){
        rep(j,1001){
            prime_count[i][j] = 0;
        }
    }
    vector<bool> exist(1000000, false);
    rep(i,N){
        ll m = 2;
        while(m <= 1000){
            if (A[i] % m == 0){
                prime_count[i][m]++;
                A[i] /= m;
            }
            else{
                m++;
            }
        }
        if (A[i] > 1000){
            exist[A[i]] = true;
        }
    }
    ll all = 1;
    rep(i,1001){
        ll max_count = 0;
        rep(j,N){
            max_count = max(max_count, prime_count[j][i]);
        }
        if (max_count >= 1){
            rep(j,max_count){
                all = (all * i) % 1000000007;
            }
        }
    }
    for (ll i = 1001; i < 1000000; i++){
        if (exist[i]) all = (all * i) % 1000000007;
    }
    ll ans = 0;
    rep(i,N){
        ans = (ans + moddividing(all, A_copy[i])) % 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 82036
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

bool table[50101];
vector<int> primes;

int main() {
  table[2] = true;
  for (int i = 3; i <= 50100; i += 2)
    table[i] = true;
  for (int i = 3; i <= 224; i += 2)
    if (table[i])
      for (int j = 3 * i; j <= 50100; j += 2 * i)
        table[j] = false;
  primes.push_back(2);
  for (int i = 3; i <= 50100; i += 2)
    if (table[i])
      primes.push_back(i);
  int n;
  while (scanf("%d", &n) == 1) {
    int i = lower_bound(primes.begin(), primes.end(), n)-primes.begin();
    printf("%d %d\n", primes[i-1], primes[i] == n ? primes[i+1] : primes[i]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 10;
const int INF = 1e9;

vector<int> solve(int a, int b, int p){
  vector<int> res;
  res.push_back(a);
  while(a != b){
    a += p;
    if(a == 10) { a = 5; p = -1; }
    if(a == -1) { a = 1; p = 1; }
    res.push_back(a);
  }
  return res;
}

int main() {
  int T; cin >>T;
  REP(t, T){
    int a, b; cin >>a >>b;
    vector<int> ans = solve(a, b, 1);
    if(a <= 5){
      vector<int> tmp = min(ans, solve(a, b, -1));
      if(tmp.size() < ans.size()) ans = tmp;
    }
    REP(i, ans.size()) cout <<ans[i] <<(i + 1 == (int)ans.size() ? "" : " ");
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
use std::collections::HashMap;

const KEYS: &[&str] = &["AC", "WA", "TLE", "RE"];

fn main() {
    let n: i32 = read();

    let mut counts: HashMap<String, i32> = KEYS.iter().map(|&k| (String::from(k), 0)).collect();

    for _ in 0..n {
        let s: String = read();
        if let Some(&c) = counts.get(&s) {
            counts.insert(s, c + 1);
        }
    }

    KEYS.iter().for_each(|&k| {
        let &c = counts.get(k).unwrap_or(&0);
        println!("{} x {}", k, c);
    });
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

vector<ll> findsumofdigits(ll n) {
  vector<ll> v(0);
  ll sum=0;
  while (n > 0) {
    v.pb(n % 10);
    sum+=n%10;
    n /= 10;
  }
  v.pb(sum);
  return v;
}


signed main(){
    ll n,ans,sum;cin>>n;
    vector<ll> v= findsumofdigits(n);
    ans=v.back();v.pop_back();
    sum=ans;

    for(int i=1;i < siz(v);i++)
    {
        sum+=(9-v[i-1]);
        if(v[i]!=0){
            sum--;
            ans=max(ans,sum);
            sum++;
        }
    }
    cout<<ans<<endl;
}

        


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc163/tasks/abc163_c

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 2*1e5;

int N;
// vector<int> A;

vector<int> ans;

int main() {
  cin >> N;
  // A = vector<int>(N - 1);
  // REP(i, N - 1) cin >> A[i];

  ans = vector<int>(N, 0);
  REP(i, N - 1) {
    int A;
    cin >> A;
    ans[A - 1]++;
  }

  REP(i, N) cout << ans[i] << endl;
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
int n,x,a[100001],ans;
inline int gcd(int aa,int b)     
{
     if (aa%b==0) return b;
       else return gcd(b,aa%b);      
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>a[0];
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a,a+n+1);
	ans=a[1]-a[0];
	for(int i=1;i<n;i++)
		ans=gcd(ans,a[i+1]-a[i]);
	cout<<ans;
}

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

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

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

	int H, W; cin >> H >> W;
	int a[1000][1000];

	vector<P> odds;

	for (int i = 1;i <= H;i++){
		for (int j = 1;j <= W;j++){
			cin >> a[i][j];
		}
	}

	for (int i = 1;i <= H;i++){
		if(i%2 == 1){
			for (int j = 1;j <= W;j++){
				if(a[i][j]%2 != 0){
					odds.push_back(P(i,j));
				}
			}
		} else {
			for (int j = W;j >= 1;j--){
				if(a[i][j]%2 != 0){
					odds.push_back(P(i,j));
				}
			}
		}
	}

	vector<P> out;
	int cnt = 0;

	for (int i = 0;i < odds.size();i+=2){
		if(i+1 >= odds.size()) break;
		P from = odds[i], to = odds[i+1];
		out.push_back(from);
		while(from != to){
			if(from.first%2 == 1){
				if(from.second == W) from = P(from.first+1,W);
				else from.second++;
			}else{
				if(from.second == 1) from = P(from.first+1,1);
				else from.second--;	
			}
			cnt++;
			out.push_back(from);
		}
		out.push_back(P(-1,-1));
	}

	cout << cnt << endl;

	for (int i = 1;i < out.size();i++){
		if(out[i] == P(-1,-1)) i+=2;
		if(i >= out.size()) break;
		cout << out[i-1].first << " " <<  out[i-1].second
				<< " " << out[i].first << " " << out[i].second << endl;
	}
	return 0;

}


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define int long long 

int32_t main(){
    ios::sync_with_stdio(0);cin.tie(0);
    
    int n;
    cin>>n;

    long double ans=0.5;
    if(n&1){
        ans=((n-n/2)*1.0)/n;
    }

    cout<<fixed<<setprecision(12)<<ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	for (int i = 0; i < 5	; i++) {
		int a; cin >> a;
		if (a == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3584
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

int n;
ll a[410],b[410];
ll dp[410][410];

int main(void){
    cin >> n;
    REP(i,n){
        cin >> a[i];
        b[i+1] = b[i] + a[i];
    }
    REP(i,n+1)REP(j,n+1)dp[i][j] = (1LL << 55);
    REP(i,n)dp[i][i+1] = 0;

    for(int d = 2;d <= n;d++){
        for(int l = 0;l + d <= n;l++){
            int r = l + d;
            if(d == 2)dp[l][r] = b[r] - b[l];
            else{
               for(int k = l + 1;k <= r - 1;k++){
                   chmin(dp[l][r] , dp[l][k] + dp[k][r] + (b[r] - b[l]));
               }            
            }
        }
    }
    cout << dp[0][n] << '\n';
}
/*
 * ちょっと待って！
 * そのコード本当に提出して大丈夫？
 * たくさんのコーナーケースがあるよ！
 * 君の注意力は大したことないよ！
 * WAを出すと君は冷静さを失うよ！
 * */


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.concurrent.ThreadLocalRandom;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static void solve(long n, long x, long m) {
    Map<Long, Integer> a2 = new HashMap<>();
    long[] a = new long[(int) m + 1];
    a2.put(x, 0);
    a[0] = x;
    int from = -1, to = -1;
    for (int i = 1; i < n; i++) {
      a[i] = (a[i - 1] * a[i - 1]) % m;
      if (a2.containsKey(a[i])) {
        from = a2.get(a[i]);
        to = a2.get(a[i - 1]);
        break;
      }
      a2.put(a[i], i);
    }
    long sum = 0L;
    if (from >= 0) {
      for (int i = 0; i < from; i++) sum += a[i];
      n -= from;
      long intervalSum = 0L;
      for (int i = from; i <= to; i++) intervalSum += a[i];
      long interval = (long) (to - from + 1);
      sum += (n / interval) * intervalSum;
      n %= interval;
    } else {
      from = 0;
    }
    for (int i = 0; i < (int) n; i++) {
      sum += a[from + i];
    }
    System.out.println(sum);
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long n = sc.nextLong();
    long x = sc.nextLong();
    long m = sc.nextLong();
    solve(n, x, m);
  }
}

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

int main() {
  int N, X;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0; i < N; i++){
     cin >> A.at(i);
  }
  for(int i = 0; i < N; i++){
      cin >> B.at(i);
  }
  X = 0;
  for(int i = 0; i < N; i++){
      if(A.at(i) > B.at(i)){
        X = X + A.at(i) - B.at(i);
      }
  }
       cout << X << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  char a;
  cin >> a;
  if(a == 'A'){
    cout << 'T' << endl;
  } else if(a == 'T'){
    cout << 'A' << endl;
  } else if(a == 'G'){
    cout << 'C' << endl;
  } else if(a == 'C'){
    cout << 'G' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,k=[int(i) for i in input().split()]
mod=10**9+7
def part_sum(start,k):
    return k*(k+1)//2+(k*(start-1))

def count_sum(k):
    return part_sum(n-k+1,k)-part_sum(0,k)+1
ans=0
for i in range(k,n+2):
    ans+=count_sum(i)
    ans=ans%mod
print(ans)

Measured memory_bytes: 65264
using System;

class Program
{
    static void Main(string[] args)
    {
        var A = int.Parse(Console.ReadLine());
        var B = int.Parse(Console.ReadLine());
        var C = int.Parse(Console.ReadLine());
        var X = int.Parse(Console.ReadLine());
        var count = 0;

        for(int i=0; i<=A; i++)
        {
            for(int j=0; j<=B; j++)
            {
                for(int k=0; k<=C; k++)
                {
                    if(500*i + 100*j + 50*k == X) { ++count; }
                }
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=350;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	for(int i=0;i<100;i++)
		for(int j=0;j<100;j++)
			if(i*4+j*7==N){
				cout<<"Yes"<<endl;
				return 0;
			}
	cout<<"No"<<endl;
	return 0;
}

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

int main(){
	ll n, a, b; cin >> n >> a >> b;
	ll x[n];
	for(ll i = 0; i < n; ++i) cin >> x[i];
	ll ans = 0;
	for(ll i = 1; i < n; ++i){
		ans += min(b, a * (x[i] - x[i - 1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]

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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

use std::cmp::{min, max};
use std::collections::{HashMap, HashSet, VecDeque, BinaryHeap};

fn main() {
    input!{
        a: usize,
        b: usize
    }
    println!("{}", a * b);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+6;
vector<int>g[MAX];
vector< vector < int > >v1;
vector<int>vec;
int vis[MAX],x[MAX],y[MAX],p[MAX],n,m,vis2[MAX];
void dfs(int u){
    vis[u]=true;
    vec.push_back(u);
        for(int i=0;i<g[u].size();i++)
                if(!vis[g[u][i]])
                    dfs(g[u][i]);

}
long long cnt;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>p[i];

    for(int i=1;i<=m;i++ ){
        cin>>x[i]>>y[i];
        g[y[i]].push_back(x[i]);
        g[x[i]].push_back(y[i]);
    }

    for(int i=1;i<=m;i++){
            vec.clear();
            if(!vis[x[i]]){
            dfs(x[i]);
            v1.push_back(vec);
            }
    }

    for(int i=1;i<=n;i++){
            if(vis[i]==0 &&  i==p[i]){
                cnt++;
                vis2[i]=1;
            }
    }

   // cout<<cnt<<endl;
  //  sort(v1.begin(),v1.end());
 //   cout<<"TTTTTTTTTT"<<endl;
    for(int i=0;i<v1.size();i++){
            vec.clear();
            for(int j=0;j<v1[i].size();j++){
                    vec.push_back(p[v1[i][j]]);
            }
      //      cout<<"FFFFFF"<<endl;
            sort(vec.begin(),vec.end());
            sort(v1[i].begin(),v1[i].end());
        /*    for(int k=0;k<vec.size();k++)
                cout<<vec[k]<<" ";
            cout<<endl;
            for(int k=0;k<vec.size();k++)
                cout<<v1[i][k]<<" ";
                cout<<endl;
                */
            int j=0,k=0;
            while(j<vec.size() && k<vec.size()){
                if(v1[i][j]==vec[k]){
                    k++;
                    j++;
                    cnt++;
                }else if(v1[i][j]>vec[k])
                    k++;
                    else
                        j++;

            }
    }
    cout<<cnt;
    return 0;
}


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

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	
};


struct edge{
	int a,b,cost;
	
	bool operator<(const edge& o) const{
		return cost < o.cost;
	}
};
// クラスカル法
// nは頂点数
ll kruskal(vector<edge> es, int n){
	sort(es.begin(), es.end());
	UnionFind uf(n);
	ll res = 0;
	
	rep(i, es.size()){
		edge& e = es[i];
		if(!uf.issame(e.a, e.b)){
			res += e.cost;
			uf.merge(e.a, e.b);
		}
	}
	return res;
}


bool compbya(const T &left, const T &right){
	return get<0>(left) < get<0>(right);
}
bool compbyb(const T &left, const T &right){
	return get<1>(left) < get<1>(right);
}

int main(){

	int n;
	cin >> n;
	vector<T> inputs(n);
	rep(i,n){
		int a,b;
		cin >> a >> b;
		inputs[i] = make_tuple(a,b,i);
	}
	
	vector<edge> es;
	
	sort(inputs.begin(), inputs.end(), compbya);
	rep(i,n-1){
		int dist = abs(get<0>(inputs[i]) - get<0>(inputs[i+1]));
		es.push_back(edge{get<2>(inputs[i]), get<2>(inputs[i+1]), dist});
	}
	
	sort(inputs.begin(), inputs.end(), compbyb);
	rep(i,n-1){
		int dist = abs(get<1>(inputs[i]) - get<1>(inputs[i+1]));
		es.push_back(edge{get<2>(inputs[i]), get<2>(inputs[i+1]), dist});
	}
	
	cout << kruskal(es,n) << endl;
	return 0;
}

Measured memory_bytes: 9584
import collections

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()

if N == 1:
  print(1)
  exit()

pq = []
for i in range(N):
  xi, yi = xy[i][0], xy[i][1]
  for j in range(i + 1, N):
    xj, yj = xy[j][0], xy[j][1]
    p, q = xj - xi, yj - yi
    pq.append((p, q))
#print(pq)

c = list(collections.Counter(pq).values())
c.sort()
print(N - c[-1])

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;
    if (a == 1)
        a = 14;
    if (b == 1)
        b = 14;

    if (a == b)
        cout << "Draw";
    else if (a > b)
        cout << "Alice";
    else
        cout << "Bob";
    cout << endl;
}

Measured memory_bytes: 3652
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 998244353;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N,M;cin >> N >> M;
    vector<vector<char>> ban(N,vector<char>(N));
    vector<vector<char>> temp(M,vector<char>(M));
    for(int i = 0;i<N;i++)for(int j = 0;j<N;j++) cin >> ban.at(i).at(j);
    for(int i = 0;i<M;i++)for(int j = 0;j<M;j++) cin >> temp.at(i).at(j);

    bool ok = true;
    //左上をi,jで決めておく
    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            //M*Mを全探索
            for(int k = 0;k<M;k++){
                for(int l = 0;l<M;l++){
                    if(k+i >= N || l+j >= N) {
                        ok = false;
                        continue;
                    }
                    if(ban.at(k+i).at(l+j) != temp.at(k).at(l)) ok = false;
                }
            }
            if(ok){
                cout << "Yes" << endl;
                return 0;
            }
            ok = true;
        }
    }
    cout << "No" << endl;

}


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

struct E {
  int t,x,y;
};
int main()
{
  int N;
  std::cin >> N;
  int pt = 0, px = 0, py = 0;
  for (int i=0; i<N; ++i) {
    int t, x, y;
	std::cin >> t >> x >> y;
    int dx = std::abs(x - px);
    int dy = std::abs(y - py);
    int dt = t - pt;
    if (dx + dy > dt) { std::cout << "No" << std::endl; return 0; }
    if ((dx + dy) % 2 != dt %2) { std::cout << "No" << std::endl; return 0; }
    pt = t; px = x; py =y;
  }
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int unsigned long long int
using namespace std;
int calculate(int a, int b) {
    if(a%b == 0)
        return a;
    return b*(a/b + 1);
}
int calc(int a, int b) {
    if(a%b == 0)
        return a;
    return b*(a/b); 
}
int get(int lcm, int a, int b) {
    if(a%lcm == 0 && b%lcm == 0)
        return (b/lcm- a/lcm + 1);
    if(a%lcm == 0 && b%lcm != 0)
        return (b/lcm - a/lcm + 1);
    if(a%lcm != 0 && b%lcm == 0)
        return (b/lcm - a/lcm);
    return (b/lcm - a/lcm);
}
void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int start_6 = calculate(a, c);
    int start_8 = calculate(a, d);
    int end_6 = calc(b, c);
    int end_8 = calc(b, d);
    int lcm = (c*d)/__gcd(c, d);
    cout << (b-a+1) - (end_6/c - start_6/c + 1)  - (end_8/d - start_8/d + 1) + get(lcm, a, b) << '\n';
    return ;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

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

int A[100009];

int main() {
	int N; long long as = 0, bs = 0; scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf("%d",&A[i]);
	for(int i=1, sa = 0, sb = 0; i<=N; i++) {
		sa += A[i]; sb += A[i];
		if(i%2) {
			if(sa >= 0) as += sa + 1, sa = -1;
			if(sb <= 0) bs += 1 - sb, sb = +1;
		}
		else {
			if(sa <= 0) as += 1 - sa, sa = +1;
			if(sb >= 0) bs += sb + 1, sb = -1;
		}
	}
	printf("%lld", min(as, bs));
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from collections import deque, Counter

N = int(input())
X = [[] for i in range(N)]
L = [0]*N
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)
    L[x-1] += 1
    L[y-1] += 1

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

C = Counter(P)
##### Settings
unit = 0
merge = lambda a, b: a + b
adj_bu = lambda a, i: (a+1)/C[P[i]]
adj_td = lambda a, i, p: ((XX[P[i]]*L[P[i]]-XX[i]*C[P[i]])/max(1,L[P[i]]-1)+1)/max(1,C[i])
adj_fin = lambda a, i: a*max(1,C[i])/L[i]
#####

ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in R[1:][::-1]:
    XX[i] = adj_bu(ME[i], i)
    p = P[i]
    ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_fin(ME[R[0]], R[0])

for i in R:
    ac = TD[i]
    for j in X[i]:
        TD[j] = ac
        ac = merge(ac, XX[j])

    ac = unit
    for j in reversed(X[i]):
        TD[j] = adj_td(merge(TD[j], ac), j, i)
        ac = merge(ac, XX[j])
        XX[j] = adj_fin(merge(ME[j], TD[j]), j)

print(*XX, sep = "\n")

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

	int n, m;
	cin >> n >> m;
	vector <ii> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;
	sort(all(v));
	ll res = 0;
	for(auto x : v){
		if(m >= x.second){
			m -= x.second;
			res += 1ll * x.first * x.second;
		}
		else{
			res += 1ll * x.first * m;
			break;
		}
	}
	cout << res;
}

Measured memory_bytes: 1024
N = gets.to_i
A = gets.split.map(&:to_i)

def gte(start)
  current = A[start]
  (start...N).each do |i|
    next_v = A[i]
    if next_v < current
      return i
    end
    current = next_v
  end
  return N
end

def lte(start)
  current = A[start]
  (start...N).each do |i|
    next_v = A[i]
    if A[i] > current
      return i
    end
    current = next_v
  end
  return N
end


ans = 0
i = 0
while i < N
  i = [gte(i), lte(i)].max
  ans += 1
end
puts ans

Measured memory_bytes: 11020
#include <stdio.h>
#include <stdlib.h>
struct Node{
  int depth;
  int height;
  int p;//parent
  int l,r;
  int id;
  int c;
} ;

int getHeight(int);

struct Node *tree;
int main(){
  
  int i,j,n,a,id,c,x,y,x1,x2;
  
  scanf("%d",&n);
  tree = malloc(sizeof(struct Node)*n);
  
  for(i=0;i<n;i++){
    tree[i].p = tree[i].l = tree[i].r = -1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&id);
    tree[id].id = id;
    scanf("%d%d",&tree[id].l,&tree[id].r);
  }


  /*for(j=0;j<2;j++){
    printf("fuck\n");
    if(j==0)c = tree[i].l;
    if(j==1)c = tree[i].r;
    if(j==0){
      tree[tree[i].id].l = c;
      tree[c].p = tree[i].id;
      a = c;
    }else{
      tree[a].r = c;
      tree[c].p = tree[i].id;
      a = c;
    }
    }*/
  
  for(i=0;i<n;i++){//getChildren
    tree[i].c=0;
    if(tree[i].l != -1)tree[i].c++;
    if(tree[i].r != -1)tree[i].c++;
  }
  
  for(i=0;i<n;i++){//findParent
    for(j=0;j<n;j++){
      if(tree[i].id == tree[j].l)tree[i].p = tree[j].id;
      else if(tree[i].id == tree[j].r)tree[i].p = tree[j].id;
    }
  }
  
  for(i=0;i<n;i++){//getDepth
    x=0;
    y=i;
    while(tree[y].p>-1){
      y = tree[y].p;
      x++;
    }
    tree[i].depth = x; 
  }

  for(i=0;i<n;i++){//getHeight
    x1=0;
    y=i;
    while(tree[y].l>-1){
      y = tree[y].l;
      x1++;
    }

    x2=0;
    y=i;
    while(tree[y].r>-1){
      y = tree[y].r;
      x2++;
    }
    
    if(x1>=x2)tree[i].height = x1;
    else if(x1<x2)tree[i].height = x2;
  }

  for(i=0;i<n;i++)tree[i].height = getHeight(i);
  
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].p);
    if (tree[i].p == -1)printf("sibling = -1, ");
    else if(tree[tree[i].p].l == i)printf("sibling = %d, ",tree[tree[i].p].r);
    else if(tree[tree[i].p].r == i)printf("sibling = %d, ",tree[tree[i].p].l);
    
    //getChildren;
    c=0;
    if(tree[i].l != -1)c++;
    if(tree[i].r != -1)c++;
    printf("degree = %d, ",c);
    
    printf("depth = %d, ",tree[i].depth);
    printf("height = %d, ",tree[i].height);
    
    
    
    
    if(tree[i].p == -1)printf("root");
    else if(tree[i].l == -1 && tree[i].r == -1)printf("leaf");
    else printf("internal node");
    printf("\n");
    /*printf("[");
    if(tree[i].l != -1){
      printf("%d",tree[i].l);
      a = tree[i].l;
      while(1){
        if(tree[a].r == -1)break;
        printf(", %d",tree[a].r);
        a = tree[a].r;
      }
    }
    printf("]\n"); */
  }
  

  free(tree);
  
  
  return 0;
}

int getHeight(int i){
  int a=0,b=0;

  if(tree[i].l == -1 && tree[i].r == -1)return 0;
  else {
    if(tree[i].l != -1)a += getHeight(tree[i].l)+1;
    if(tree[i].r != -1)b += getHeight(tree[i].r)+1;
    if(a >= b) return a;
    else return b;
  }
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    int n; cin>>n;
    vector<int> a(n+2,0);
    rep(i,n)cin>>a.at(i+1);
    int dis=abs(a.at(1));
    rep(i,n){
        dis+=abs(a.at(i+2)-a.at(i+1));
    }
    rep(i,n){
        int ans;
        ans=dis-abs(a.at(i+1)-a.at(i))-abs(a.at(i+2)-a.at(i+1))+abs(a.at(i+2)-a.at(i));
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2048
import sys
input=sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))

def runLength(s):
    a = []
    for c in s:
        if len(a)==0 or a[-1][0]!=c:
            a.append([c,1])
        else:
            a[-1][1] += 1
    return a

r = runLength(a)
ans = 0
for i in r:
    ans += i[1]//2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    int N,M; cin >> N >> M;
    vi G[N];
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].eb(b);
        G[b].eb(a);
    }
    rep(i,N){
        cout << G[i].size() << endl;
    }
}

Measured memory_bytes: 256
// to format a document: ctrl + K -> ctrl + D

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; i++) {
        cin >> a[i];
    }

    vector<bool> r(H, false), c(W, false);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (a[i][j] == '#') {
                r[i] = true;
                c[j] = true;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        bool flag = false;
        for (int j = 0; j < W; j++) {
            if (r[i] && c[j]) {
                cout << a[i][j];
                flag = true;
            }
        }
        if (flag) cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<bitset>
using namespace std;

const int MAX = 8000;
const char FORWARD = 'F';
const char TURN = 'T';

int main() {
	string s;
	int x, y;
	cin >> s >> x >> y;
	
	const char *S = s.c_str();
	
	for (;*S == FORWARD;++ S) -- x; // 最初の文字数だけxを減らす
	x = x < 0 ? -x : x;
	y = y < 0 ? -y : y;
	
	bitset<MAX> dpX(1), dpY(1); // 部分和問題はdpで解けるよ
	int xSum = 0, ySum = 0, xGo, yGo;
	
	for (++ S;*S != '\0';++ S) {
		xGo = 0, yGo = 0; // 連続した移動の長さ
		for (;*S == FORWARD;++ S) ++ yGo; // y軸方向
		dpY |= dpY << yGo;
		ySum += yGo;
		for (++ S;*S == FORWARD;++ S) ++ xGo; // x軸方向
		dpX |= dpX << xGo;
		xSum += xGo;
	}
	
	if (xSum >= x && (xSum - x & 1) == 0 && dpX[xSum - x >> 1] && ySum >= y && (ySum - y & 1) == 0 && dpY[ySum - y >> 1]) cout << "Yes"; // 例えば左右に合計100マス動けるとして、目的地が20なら丁度60動けるような部分和があれば移動可能、と考えるよ
	else cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、x方向とy方向はそれぞれ独立に求めることができる
最初に、Tが出てくるまで自分を動かしてしまう
そうすると、残りはどちらの方向にも動けるので、左右か上下ということさえ分かっていれば左と右および上と下の区別をつける必要はない
この時、部分和問題を解けば答えが分かる

ちょっと高速化に手を出してみたけど、お陰で闇コードがあるから怖いね
やっぱこういうのやるべきではないわ
*/

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main()
    {
        string[] Input = Console.ReadLine().Split(' ');
        int N = int.Parse(Input[0]);
        int K = int.Parse(Input[1]);
        long[] h = new long[N];
        long[] H = new long[N];
        long[] tmp = new long[N];

        long[,] Baketu = new long[10, N];
        long[] BaketuNumber = new long[10];   //0~9まで保存する
        

        for (int i = 0; i < N; i++)
        {
            h[i] = long.Parse(Console.ReadLine());
            H[i] = 0;
            tmp[i] = h[i];
        }

        //入力完了

        //とりあえずBaketuNumberを全部0にする
        //その後10回基数ソートする

        for (int i = 0; i < 10; i++)
        {
            BaketuNumber[i] = 0;
        }

        for (int i = 0; i < 10; i++)
        {
//            Console.WriteLine("\n");
//            long cnt = 0;

            for (int j = 0; j < N; j++)
            {
                tmp[j] = h[j];
                for (int k = 0; k < i; k++)
                {
                    tmp[j] /= 10;
                }
//                Console.WriteLine("{0} {1}", tmp[j], i);
                //まずバケツナンバーに1の位の数を入れる
                //バケツナンバー、バケツに入っている要素数
                BaketuNumber[tmp[j] % 10]++;
                //バケツナンバー、バケツのそのままの値
                Baketu[tmp[j] % 10, BaketuNumber[tmp[j] % 10] - 1] = h[j];

//                cnt++;
                //ここでtmp[j] % 10がひとけた上の数字をとれるようにする
            }

            int cnt2 = 0;
            int cnt3 = 0;

            for (int j = 0; j < N; j++)
            {

                bool check = false;
                do
                {
                    //でそれから新しいHにそれを入れる
                    if (BaketuNumber[cnt2] > 0) //もしn(0~9)番目のバケツに入ってたら
                    {
                        //まずh[j]に入れる
                        h[j] = Baketu[cnt2, cnt3];
                        Baketu[cnt2, cnt3] = 0;
                        cnt3++;

                        BaketuNumber[cnt2]--;

                        check = true;
                    }
                    else
                    {
                        cnt2++;
                        cnt3 = 0;
                    }
                } while (check == false);
                
            }
        }

/*        for (int i = 0; i < N; i++)
        {
            Console.WriteLine(h[i]);
        }
*/
        //iが小さい順にでかい木

        long hMin = 1000000000;

        for (int i = 0; i < N - (K - 1); i++)
        {
            if (h[i + (K - 1)] - h[i] < hMin)
            {
                hMin = h[i + (K - 1)] - h[i];
            }
        }

        Console.WriteLine(hMin);
    }
}

Measured memory_bytes: 24412
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n;
  cin >> n;
  int a;
  int cnt = 1;
  int scr = 0;
  LOOP(i,n){
    cin >> a;
    if(a==cnt){
      cnt++;
    }else{
      scr++;
    }
  }
  if(scr==n)cout << -1 << endl;
  else  cout << scr << endl;
}


Measured memory_bytes: 256
var n, ans, i : integer;
    v, c : array[1..20] of integer;
begin
  readln(n);
  for i := 1 to n do read(v[i]);
  for i := 1 to n do read(c[i]);
  ans := 0;
  for i := 1 to n do
  begin
    if v[i] - c[i] > 0 then ans := ans + v[i] - c[i]
  end;
  writeln(ans);
end.

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

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

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

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

	return 0;
}


Measured memory_bytes: 640
import math, sys

X = int(input())

if int(X**(1/5)) **5 ==X:
    print(*[ int(X**(1/5)) , 0])
    sys.exit()

for i in range(1,10**7):
    A = i**5
    B = A - X
    C = X - A

    if B > 0 and int(B**(1/5)) **5 == B:
        print(*[ i , int(B**(1/5)) ])
        sys.exit()

    if C > 0 and int(C**(1/5)) **5 ==C:
        print(*[ i , - int(C**(1/5)) ])
        sys.exit()

Measured memory_bytes: 62548
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li  	int64_t
#define ld  	double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl      	cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,a[MX1];

void solve(){
  li i;cin>>n;
  li cnt4=0,cnt2=0,cnt1=0;
  rep(i,0,n){
    cin>>a[i];
    if(a[i]%4==0) cnt4++;
    elif(a[i]%2==0) cnt2++;
    else cnt1++;
  }
  if(cnt2==0){
    if(cnt1<=cnt4+1) cout<<"Yes";
    else cout<<"No";
  }else{
    if(cnt1+1<=cnt4+1) cout<<"Yes";
    else cout<<"No";
  }
}

int main(){
  opt
  #ifndef ONLINE_JUDGE
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif
  li t=1;
  //cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
using P = pair<Int, Int>;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    string s, t; cin >> s >> t;

    int ans = INF;
    for(int i = 0; i < s.size(); i++)
    {
        int k = t.size();
        string tmp = s.substr(i, k);
        if(tmp.size() != t.size()) continue;
        int cnt = 0;
        for(int j = 0; j < tmp.size(); j++)
        {
            if(tmp[j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3680