akhauriyash/Code-Regression huggingface dataset:
MAX_COST = Float::INFINITY

def calc_min_costs_from(v_start, costs)
  vert_struct = Struct.new :id, :cost_from_start do
    define_method :cost_to do |v_to|
      costs[id][v_to.id]
    end

    def connected_to?(v_to)
      0 <= cost_to(v_to)
    end

    def cost_from_start_through(other_v)
      other_v.cost_from_start + other_v.cost_to(self)
    end
  end

  n_vertexes = costs.size
  verts = n_vertexes.times.map do |id|
    vert_struct.new(id, MAX_COST)
  end

  verts[v_start].cost_from_start = 0
  visiting = {}
  visiting[v_start] = verts[v_start]

  while visiting.any?
    v_from = visiting.min_by { |_, v| v.cost_from_start }[1]
    visiting.delete v_from.id

    verts.each do |v_to|
      next unless v_from != v_to && v_from.connected_to?(v_to)
      through_cost = v_to.cost_from_start_through v_from
      if through_cost < v_to.cost_from_start
        v_to.cost_from_start = through_cost
        visiting[v_to.id] = v_to
      end
    end
  end

  verts.map { |v| v.cost_from_start }
end

n_vertexes = gets.to_i
costs      = Array.new(n_vertexes) { Array.new(n_vertexes, -1) }
n_vertexes.times do
  v_from, n_degrees, *inputs = gets.split.map &:to_i
  1.step(n_degrees * 2, 2) do |i|
    v_to, cost = inputs[i - 1], inputs[i]
    costs[v_from][v_to] = cost
  end
end

min_costs = calc_min_costs_from(0, costs)
puts min_costs.map.with_index{ |cost, v| "#{v} #{cost}" }

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

typedef long long ll;

int n,x[15],y[15],p[15],D[15],d[15];
ll ans[16];

int main(){
#ifdef LOCAL
    freopen("in3.txt", "r", stdin);
    freopen("out3.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>p[i];
    memset(ans,0x3f,sizeof(ans));
    ans[0]=0;
    for(int i=0;i<n;i++){
        D[i]=min(abs(x[i]),abs(y[i]));  //D[i]存每个点到轴的最短距离
        ans[0]+=(ll)p[i]*D[i];  //d[i]表示现在的最短距离
    }
    for(int s=0;s<1<<n;s++){
        int t = s;
        do {
            memcpy(d, D, sizeof(d));
            for (int i = 0; i < n; i++) {
                if (s >> i & 1) {
                    if (t >> i & 1) {
                        for (int j = 0; j < n; j++) {
                            d[j] = min(d[j], abs(x[i] - x[j]));
                        }
                    } else {
                        for (int j = 0; j < n; j++) {
                            d[j] = min(d[j], abs(y[i] - y[j]));
                        }
                    }
                }
            }
            ll cur = 0;
            for (int i = 0; i < n; i++) {
                cur += (ll) d[i] * p[i];
            }
            ans[__builtin_popcount(s)] = min(ans[__builtin_popcount(s)], cur);
            t = (t-1)&s;
        }while (t != s);



    }
    for(int i=0;i<=n;i++)cout<<ans[i]<<'\n';

    return 0;
}

Measured memory_bytes: 3576
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
d = []

for i in range(N-1):
  tmp = t[i+1] - t[i]
  if tmp > T:
    d.append(T)
  else:
    d.append(tmp)

print(sum(d)+T)

Measured memory_bytes: 30768
#include<bits/stdc++.h>
using namespace std;
vector<int> bulb[11];
int p[11];
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=m;i++) {
        int k,s;
        cin >> k;
        for(int j=1;j<=k;j++) {
            cin >> s;
            bulb[i].emplace_back(s-1);
        }
    }
    for(int i=1;i<=m;i++) cin >> p[i];

    int ans=0;
    for(int i=0;i<(1 << n);i++) {
        bool q=1;
        for(int j=1;j<=m;j++) {
            int cnt=0;
            for(auto k : bulb[j])
                if(((1 << k)&i)>0) cnt++;
            if((cnt&1)!=p[j]) q=0;
        }
        if(q) ans++;
    }
    cout << ans;
}


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

const int nmax=8;
vector<vector<bool>> graph(nmax, vector<bool>(nmax));//隣接グラフ
vector<bool> visited(nmax);//訪問済み判定
int N, M;

int dfs(int v){

    bool all_visited=true;//すべて訪問されたか否か（初期設定はture)

    for(int i=0;i<N;++i){//ひとつでも未訪問のものがあったらfalse
        if(visited.at(i)==false) all_visited=false;
    }
    if(all_visited) return 1;//すべて訪問済みだったら

    int ret=0;//進む場所がなかったら0を返す

    for(int i=0;i<N;++i){
        if(graph.at(v).at(i)==false || visited.at(i)==true) continue;//vとiが隣接していなかったら or iが訪問済みだったら 飛ばす
        visited.at(i)=true;//訪問済み
        ret+=dfs(i);
        visited.at(i)=false;//訪問済みの解除
    }

    return ret;
}

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

    for(int i=0;i<M;++i){//隣接グラフに0オリジン(-1)で値を入れる
        int A,B;
        cin >> A >> B;
        graph.at(A-1).at(B-1)=graph.at(B-1).at(A-1)=true;
    }

    for(int i=0;i<N;++i){//すべて未訪問
        visited.at(i)=false;
    }

    visited.at(0)=true;
    cout << dfs(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool UDid(char a) {
    if ((a >= 'a') && (a <= 'z')) {
        return true;
    }
    else if ((a >= 'A') && (a <= 'Z')) {
        return false;
    }
}
int main() {
    int N, K,sum=0;
    int p[100010];
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p,p+N);
    for (int i = 0; i < K; i++) {
        sum += p[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 3136
function main(){
	var s = [];
	var x;
	while((x = scan()), x === x){
		if(x === 0){
			print(s.pop());
		}
		else{
			s.push(x);
		}
	}
}
 
function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/);
	main();
});

Measured memory_bytes: 15696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a; cin >> a;
    set<char> s;
    rep(i,a){
        char a; cin >> a;
        s.insert(a);
    }
    if(s.size()==3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }


    return 0;
}

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

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

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

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

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

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

int powmod(int a, int p, int m){
  int res = 1, tmp = a;
  while(p != 0){
    if(p % 2)
      res = (res*tmp) % m;
    tmp = (tmp*tmp) % m;
    p /= 2;
  }
  return res;
}

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int A, B; cin >> A >> B;
  cout << powmod(B, A, MOD) << endl;
}



Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int b1, b2, b3;
  cin >> b1 >> b2 >> b3;
  if(b1 == 1 && b2 == 1 && b3 == 0) cout << "Open" << endl;
  else if(b1 == 0 && b2 == 0 && b3 == 1) cout << "Open" << endl;
  else cout << "Close" << endl;
}




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

#define zton(i,n) for(int i=0;i<=n;i++)
#define oneton(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define loop(i,b,a) for(int i=a;i>=b;i--)
#define dsort(arr,n) sort(arr, arr + n, greater<int>())
#define vsortd(a) sort(a.begin(), a.end(), greater<double>())
#define vsort(a) sort(a.begin(), a.end())
#define ll long long int
#define test int tc;cin>>tc;while(tc--)
#define dbg(x) cout<<#x<<'='<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl<<#w<<"="<<(w);
#define minheap priority_queue <int, vector<int>, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define ff first
#define ss second
#define mpr make_pair
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mkv vector<int>
#define allzero(dp) memset(dp,0,sizeof(dp))
#define endl "\n"
#define print(x) cout<<x<<endl;

const int mod=1e9+7;
using namespace std;
bool sortcol( const vector<int>& v1,const vector<int>& v2 ) {return v1[1] < v2[1];}

void fastio()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

bool sortbysecdesc(const pair<ll,ll> &a,const pair<ll,ll> &b){
    if(a.first>b.first)return true;
    if(a.first==b.first)return a.second<b.second;
    return false;
}

ll power(ll x, ll y){
    ll res = 1;x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;x=(x*x)%mod;}
    return res;
}


void solve()
{
    int n;cin>>n;
    string s;cin>>s;
   // int n=s.size();
    int i=0,j=n-1;
    int c=0;
    while(i<j){
        if(s[i]=='R'&&s[j]=='W'){
            i++;j--;
        }
        else if(s[i]=='W'&&s[j]=='R'){
            swap(s[i],s[j]);
            i++;j--;
            c++;
        }
        else if(s[j]=='W')j--;
        else if(s[i]=='R')i++;
    }
    print(c)

}

int main()
{
  //  fastio();
   // test
    solve();
}


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

using namespace std;

typedef long long ll;

const int N = 1e6 + 5;
const int INF = 1e9 + 7;

ll n, d;
int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> d;
    ll c = 0;
    for(int  i = 1; i <= n; i++){
        ll x, y;
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= d){
            c++;
        }

    }
    cout << c;
    return 0;
}


Measured memory_bytes: 3688
str_in = input()
str_val = input()

for i in range(len(str_in),-1,-1):
    flag = str_val in str_in  # check if input value is in string
    if flag:
        break
    if str_val[:i] == str_in[0-i:] and str_in.find(str_val[i:]) == 0:  #first, check if substring till i-index is found in the last part of string. If yes, check rest of input value is found in the beginning of string
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7356
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let x1: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let y1: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let x2: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let y2: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let vx = x2 - x1;
    let vy = y2 - y1;
    let x3 = x2 - vy;
    let y3 = y2 + vx;
    let x4 = x1 - vy;
    let y4 = y1 + vx;
    println!("{} {} {} {}", x3, y3, x4, y4);
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;

public class Main {
    private static class Solver {
        void Solve() {
            int n = inp.nextInt();
            int k = inp.nextInt();
            List<Integer> a = new ArrayList<>();
            List<Integer> b = new ArrayList<>();

            a.add(0);
            for (int i = 1; i <= n; ++i) {
                int x = inp.nextInt();
                if (x >= 0) {
                    a.add(x);
                } else {
                    b.add(-x);
                }
            }
            b.add(0);
            Collections.reverse(b);

            int ans = (int) 2e9;
            for (int i = 0; i <= a.size() - 1; ++i) {
                int j = k - i;
                if (0 <= j && j <= b.size() - 1) {
                    int s1 = a.get(i) * 2 + b.get(j);
                    int s2 = a.get(i) + b.get(j) * 2;
                    ans = Math.min(Math.min(s1, s2), ans);
                }
            }
            out.println(ans);
        }

        static InputReader inp;
        static PrintWriter out;
    }

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

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

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

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

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

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

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Solver.inp = new InputReader(inputStream);
        Solver.out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.Solve();
        Solver.out.close();
    }
}

Measured memory_bytes: 43700
import sys
sys.setrecursionlimit(10**6)

INF = 1e8

UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3


def f(l):
    result = INF
    for v in l.values():
        v.sort()
        for i in range(1, len(v)):
            if(v[i-1][1] == UP and v[i][1] != UP):
                result = min(result, v[i][0]-v[i-1][0])
    return result


def main(input, print):
    N = int(input())

    table = [[0 for _ in range(3)] for _ in range(N)]
    for i in range(N):
        X, Y, U = map(str, input().split())
        table[i][0] = int(X)
        table[i][1] = int(Y)
        if U == 'U':
            table[i][2] = UP
        elif U == 'R':
            table[i][2] = RIGHT
        elif U == 'D':
            table[i][2] = DOWN
        elif U == 'L':
            table[i][2] = LEFT
    ans = INF
    for u in range(4):
        # UD
        l = {}
        for i in range(N):
            if table[i][2] != UP and table[i][2] != DOWN:
                continue
            key = table[i][0]
            if key not in l:
                l[key] = []
            l[key].append((table[i][1], table[i][2]))
        ans = min(ans, f(l)*5)
        # UR
        l = {}
        for i in range(N):
            if table[i][2] != UP and table[i][2] != RIGHT:
                continue
            key = table[i][0]+table[i][1]
            if key not in l:
                l[key] = []
            l[key].append((table[i][1], table[i][2]))
        ans = min(ans, f(l)*10)
        # rotate
        for i in range(N):
            temp = table[i][0]
            table[i][0] = table[i][1]
            table[i][1] = -temp
            table[i][2] = (table[i][2]+1) % 4
    if ans == INF:
        print('SAFE')
    else:
        print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 239852
#include <iostream>
#include <string> 
using namespace std;
int main(void) {
    int H,W,cnt = 0;
    cin >> H >> W;
    string A[H];
    for(int i = 0;i<H;i++) cin >> A[i];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cnt = 0;
            if(A[i][j] == '#') continue;
            for(int r=-1;r<=1;r++){
                if(r+i<0 || H<=r+i) continue;
                for(int c = -1 ;c<=1;c++){
                    if(c + j <0 || c+j >= W) continue;
                    if(c == 0 && r == 0) continue;
                    if(A[i + r][c + j] == '#') cnt++ ;
                }
            }
            A[i][j] = to_string(cnt)[0];
        }
    }
     for (int i = 0; i < H; i++) cout << A[i] << endl;
	
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int x = sc.nextInt();
		
		// 計算
		int result = 1;
		while(x > result*(result+1)/2){
		    result++;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, M, a, b, col[709], dp[709][709]; bool used[709][709], flag = false; vector<int>x[709], G1, G2;
vector<pair<int, int>>G;

void dfs(int pos, int cur) {
	if (col[pos] >= 0) {
		if (col[pos] != cur) flag = true;
		return;
	}
	col[pos] = cur; if (cur == 0) G1.push_back(pos); else G2.push_back(pos);
	for (int i = 0; i < x[pos].size(); i++) { dfs(x[pos][i], cur ^ 1); }
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		scanf("%d%d", &a, &b);
		used[a][b] = true; used[b][a] = true;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i != j && used[i][j] == false) x[i].push_back(j);
		}
	}
	for (int i = 1; i <= N; i++) col[i] = -1;
	for (int i = 1; i <= N; i++) {
		if (col[i] != -1) continue;
		G1.clear(); G2.clear();
		dfs(i, 0);
		G.push_back(make_pair(G1.size(), G2.size()));
	}
	if (flag == true) {
		cout << "-1" << endl;
		return 0;
	}
	dp[0][0] = 1;
	for (int i = 0; i < G.size(); i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j] == 0) continue;
			dp[i + 1][j + G[i].first] = 1;
			dp[i + 1][j + G[i].second] = 1;
		}
	}
	int minx = (1 << 30);
	for (int i = 0; i <= N; i++) {
		if (dp[G.size()][i] == 1) {
			int S = i*(i - 1) / 2 + (N - i)*(N - i - 1) / 2;
			minx = min(minx, S);
		}
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 3072
A, B = input().split(" ")
A = int(A)
B = int(B)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
x_A = [x[0] for x in factorization(A)]
x_B = [x[0] for x in factorization(B)]

if x_A == [1] and x_B == [1]:
  print(1)
  exit()

ans = 1
for x in x_A:
  if x in x_B:
    ans += 1

print(ans)
  



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

using namespace std;

const int maxn = 3e5 + 2101;
const int mod = 1e9 + 7;
long long BIT[maxn];
long long ops[maxn];
int f[maxn];
vector <pair <long long, long long> > inters;
vector <long long> strt;
vector < pair<pair<long long, long long>, pair<long long, long long> > > v;
long long ans[maxn];
queue <pair<long long, long long> > que;
vector <pair<long long, long long> > a;
long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

long long sum(int ind)
{
    ind++;
    long long s = 0;
    while (ind > 0)
    {
        s += BIT[ind];
        ind -= ind & (-ind);
    }
    return s;
}

void update(long long x, long long ind, long long sz)
{
    ind++;
    while(ind <= sz)
    {
        BIT[ind] += x;
        ind += ind & (-ind);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, q, nn, mm;
    cin >> nn >> mm;
    n = mm + 1;
    for (int i = 0; i < nn; i++)
    {
        int t1, t2;
        cin >> t1 >> t2;
        f[t1]++;
        inters.push_back(make_pair(t1, t2));
    }
    sort(inters.begin(), inters.end());
    for (int i = 0; i < inters.size(); i++)
    {
        a.push_back(make_pair(inters[i].second, i));
        strt.push_back(inters[i].first);
    }
    long long hgt = 0;
    for (int i = 0; i <= mm; i++)
    {
        ops[i] = f[i] + hgt;
        hgt = ops[i];
    }
    long long g = 0;
    for (int i = 0; i < mm; i++)
    {
        long long cmt = ops[0];
        g++;
        for (int j = g; j <= mm; j += g)
        {
            long long yp = ops[j] - ops[j - g];
            cmt += yp;
            long long t, b, k;
            k = j;
            b = upper_bound(strt.begin(), strt.end(), j) - strt.begin();
            t = upper_bound(strt.begin(), strt.end(), j - g) - strt.begin();
            b--;
            if (b < t){continue;}
            v.push_back(make_pair(make_pair(k, i), make_pair(t, b)));
        }
        ans[i] = cmt;
    }
   	sort(v.begin(), v.end());
   	sort(a.begin(), a.end());
   	for (int i = 0; i < a.size(); i++){que.push(a[i]);}
   	for (int i = 0; i < v.size(); i++)
   	{
        int r = v[i].second.second;
        int l = v[i].second.first;
        int id = v[i].first.second;
        long long u = v[i].first.first;
        while(que.size() && que.front().first < u)
        {
            update(1, que.front().second, 302100);
            que.pop();
        }
        l--;
        if (l == -1){ans[id] -= sum(r); continue;}
        ans[id] -= (sum(r) - sum(l));
   	}
    for (int i = 0; i < mm; i++){cout << ans[i] << endl;}
    return 0;
}

Measured memory_bytes: 96480
#include <stdio.h>   
int main(void) 
{ 
    int i,n,b,f,r,v;  
    int house[4][3][10] = {0};  
    scanf("%d",&n);  
    for (i=0; i<n; i++) {   
      scanf("%d %d %d %d",&b,&f,&r,&v);  
      house[b-1][f-1][r-1] += v;  
    }   
    for (b=0; b<4; b++) {   
      for (f=0; f<3; f++) {     
        for (r=0; r<10; r++) {         
          printf(" %d",house[b][f][r]);    
        }     
        printf("\n");   
      }     
    if(b != 3) printf("####################\n");   
    }  
    return 0; 
}

Measured memory_bytes: 612
//This code is written by Shammi Anand
#include<bits/stdc++.h>
using namespace std;

#define ll              long long
#define Max(a,b,c)      max(a,max(b,c))
#define Min(a,b,c)      min(a,min(b,c))
#define pb              push_back
#define mp              make_pair
#define f               first
#define s               second
#define mod             1000000007
#define nl              "\n"
#define w(x)            int x; cin>>x; while(x--)


void shammi() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

const int N = 100005;
int n;
int dp[N];

int height[N];


int calculate(int height[], int pos) {
	if (pos == n) {
		return 0;
	}
	if (dp[pos] != -1) {
		return dp[pos];
	}
	if (pos == n - 1) {
		return dp[pos] = calculate(height, pos + 1) + abs(height[pos] - height[pos + 1]);
	} else {
		return dp[pos] = min(calculate(height, pos + 1) + abs(height[pos] - height[pos + 1]), calculate(height, pos + 2) + abs(height[pos] - height[pos + 2]));
	}
}



int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> height[i];
	}
	memset(dp, -1 , sizeof(dp));
	cout << calculate(height, 1) << nl;
	return 0;
}

Measured memory_bytes: 8268
N = int(input())
CSF = []
for i in range(N-1):
    CSF.append(list(map(int,input().split())))

for i in range(N):
    if i == N-1:
        print(0)
    else:
        ans = CSF[i][1]
        for j in range(i,N-1):
            if ans < CSF[j][1]:
                ans = CSF[j][1]
            elif ans%CSF[j][2] != 0:
                ans += (CSF[j][2]-ans%CSF[j][2])
            ans += CSF[j][0]
        print(ans)

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  ll dp[200000];
  scanf("%lld",&n);
  m=121;
  for(i=-m;i<=m;i++){
    for(j=-m;j<=m;j++){
      if(powl(i,5)-powl(j,5)==n){
        printf("%lld %lld",i,j);
        return 0;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main(){
    ll h, w;
    cin >> h >> w;
    ll ans = 1e18;
    if(h%3==0||w%3==0){
        cout << 0 << endl;
        return 0;
    }else{
        ll s = h/3;
        ll t = (h+2)/3;
        {// s
            ll a1 = (h-s)*(w/2);
            ll a2 = (h-s)*(w-w/2);
            ll nowmin = min({a1, a2, w*s});
            ll nowmax = max({a1, a2, w*s});
            chmin(ans, nowmax-nowmin);
        }
        {
            ll a1 = (h-t)*(w/2);
            ll a2 = (h-t)*(w-(w/2));
            ll nowmin = min({a1, a2, w*t});
            ll nowmax = max({a1, a2, w*t});
            chmin(ans, nowmax-nowmin);
        }
        swap(h,w);
        s = h/3;
        t = (h+2)/3;
        {// h
            ll a1 = (h-s)*(w/2);
            ll a2 = (h-s)*(w-w/2);
            ll nowmin = min({a1, a2, w*s});
            ll nowmax = max({a1, a2, w*s});
            chmin(ans, nowmax-nowmin);
        }
        {
            ll a1 = (h-t)*(w/2);
            ll a2 = (h-t)*(w-w/2);
            ll nowmin = min({a1, a2, w*t});
            ll nowmax = max({a1, a2, w*t});
            chmin(ans, nowmax-nowmin);
        }
        {
            chmin(ans, w);
            chmin(ans, h);
        }
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let ABS =
        List.init (N - 1) (fun i ->
            reads int
            |> fun [a;b] -> (a - 1, b - 1, i)
        )

    // eprintfn "ABS: %A" ABS

    let graph =
        let g = Array.init N (fun _ -> [])
        List.iter (fun (a, b, i) ->
            g.[a] <- (b, i) :: g.[a]
            g.[b] <- (a, i) :: g.[b]
        ) ABS
        Array.map List.toArray g

    // eprintfn "graph: %A" graph

    let ans = Array.create (N - 1) -1
    let rec dfs pid pcolor x =
        let mutable color = 1
        Array.iter (fun (a, i) ->
            if a <> pid then
                if color = pcolor then color <- color + 1
                ans.[i] <- color
                dfs x color a
                color <- color + 1
        ) graph.[x]

    graph
    |> Array.map Array.length
    |> Array.max
    |> printfn "%i"

    dfs -1 -1 0

    ans
    |> Array.iter (fun c -> printfn "%i" c)

    0

Measured memory_bytes: 45404
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    //入力
    int n;
    cin>>n;
    vector<vector<pair<int,int>>> edge(n+5);
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge[a].push_back({b,c});
        edge[b].push_back({a,c});
    }
    int q,k;
    cin>>q>>k;
    vector<pair<int,int>> que(q+5);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        que[i]={x,y};
    }
    //ダイクストラ
    vector<ll> dist(n+5,1ll<<60);
    dist[k]=0;
    vector<int> visit(n+5);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>> > queue;
    queue.push({dist[k],k});
    //for(int i=0;i<n;i++) queue.push({dist[i],i});
    while(!queue.empty()){
        int sec=queue.top().second;
        queue.pop();
        visit[sec]=1;
        for(int i=0;i<edge[sec].size();i++){
            int e1=edge[sec][i].first,e2=edge[sec][i].second;
            if(visit[e1]==0 && dist[e1]>dist[sec]+e2) {
                dist[e1]=dist[sec]+e2;
                queue.push({dist[e1],e1});
            }
        }
    }
    //出力
    for(int i=0;i<q;i++) cout<<dist[que[i].first]+dist[que[i].second]<<endl;
    return 0;
}


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

using namespace std;

int N, A[100100];
int memo[100100];
int dp(int n) {
	if (n <= 1) return 0;
	int &ans = memo[n];
	if (ans != -1) return ans;
	ans = min(dp(n - 1) + abs(A[n] - A[n - 1]), dp(n - 2) + abs(A[n] - A[n - 2]));

	return ans;
}
int main() {
	memset(memo, -1, sizeof(memo));
	cin >> N;
	A[0] = -(1e9 + 7);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	cout << dp(N) << endl;
	return 0;
}

Measured memory_bytes: 2560
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	string s;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		s = adapter.readln();
	}
}

struct Output
{
}

auto main2(Input* input)
{
    if (input.s[$-1] == 's')
        return input.s ~ "es";
    else
        return input.s ~ "s";
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`apple`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "apples");
	}

	unittest // example2
	{
		string example =
`bus`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "buses");
	}

	unittest // example3
	{
		string example =
`box`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "boxs");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
        string ret;
		auto i = _s.countUntil("\n");
		if (i == -1) { ret = _s; _s = ""; }
        else { ret = _s[0..i]; _s = _s[i+1..$]; }
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector <ll> count(4,0);
    vector <string> X={"AC", "WA", "TLE", "RE"};
    loop(i,0,N)
    {
        string s;
        cin >> s;
        for (int j=0; j<4; ++j) if (s==X[j]) count[j]++;
    } 
    for (int i=0; i<4; ++i) cout << X[i] << " x " << count[i] << "\n";
    return 0;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


template<class S = int, S nil = INT_MAX, class T = std::less<S> >
class RMQ {//RangeMinimum(Maximum)Query
	int n;
	S* dat;
	S query(int a, int b, int k, int l, int r)const {
		if (r <= a || b <= l)return nil;
		if (a <= l && r <= b)return dat[k];
		return std::min(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r), T());
	}
public:
	RMQ(int n = 1 << 20) :n(n) {//サイズは2のべき乗にしたほうが速い
		dat = new S[2 * n - 1];
		for (int i = 0; i < 2 * n - 1; i++)dat[i] = nil;
	}
	~RMQ() {
		delete[] dat;
	}
	void update(int k, S a) {//k番目をaに変更
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = std::min(dat[k * 2 + 1], dat[k * 2 + 2], T());
		}
	}
	S query(int a, int b)const {//[a,b)の最小(大)値
		return query(a, b, 0, 0, n);
	}
};


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

	int n, m;
	cin >> n >> m;
	
	vector<tuple<int, int, int>> e;
	rep(i, m) {
		int l, r, c;
		cin >> l >> r >> c;
		e.emplace_back(l - 1, r - 1, c);
	}
	sort(all(e));


	RMQ<long long, 1LL<<60> rmq;
	rmq.update(0, 0);
	rep(i, m) {
		int l, r, c;
		tie(l, r, c) = e[i];
		long long x = rmq.query(l, r + 1) + c;
		long long y = rmq.query(r, r + 1);
		if(x < y) rmq.update(r, x);
	}
	long long ans = rmq.query(n - 1, n);
	if (ans==(1LL<<60)) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 17908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ap = br.readLine().split(" ");
        int a = Integer.parseInt(ap[0]);
        int p = Integer.parseInt(ap[1]);
        System.out.println(problem128a(a, p));
    }

    private static int problem128a(int a, int p) {
        return (a * 3 + p) / 2;
    }
}

Measured memory_bytes: 20820
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    string x;
    cin >> x;
    int N = x.size();
    vector <char> f(N);
    int res;
    for(int bit = 0; bit < (1<<N); ++bit){
        res = x[0] - '0';
        for(int i = 1; i < N; i++){
            if(bit & (1<<i)) {
                res -= x[i] - '0';
                f[i] = '-';
            }
            else {
                res += x[i] - '0';
                f[i] = '+';
            }
        
        }
        if(res == 7){
            break;
        }
    }
    cout << x[0] << f[1] << x[1] << f[2] << x[2] << f[3] << x[3] << "=7" << endl;;
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var D = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToList();
            D.Sort();
            var max = D[N / 2];
            var min = D[N / 2-1];
            Console.WriteLine(max-min<0?0: max - min);
        }
    }
}


Measured memory_bytes: 19680
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

class Program
{
    /// <summary>
    /// 市を表します.
    /// </summary>
    class City
    {
        public City(int parent, int year)
        {
            this.Parent = parent;
            this.Year = year;
        }

        public int Parent { get; set; }
        public int Year { get; set; }

        // 県内で何番目に生まれたかを表します.
        public int InParentIndex { get; set; }
    }

    static void Main(string[] args)
    {
        // N個の県と M個の属する市を受け取ります.
        var parameter = Console.ReadLine().Split(' ').Select( x => int.Parse(x) ).ToArray();
        var N = parameter[0];
        var M = parameter[1];

        City []cities = new City[M];
        City []sequencialCities = new City[M];

        // 市のパラメーターを入力してもらいます.
        for(int i = 0; i < M; ++i)
        {
            var cityParameter = Console.ReadLine().Split(' ').Select( x => int.Parse(x) ).ToArray();

            // 県、年.
            var city = new City(cityParameter[0], cityParameter[1]);
            
            cities[i] = city;

            // 入力された並び順を記憶しておきます.
            // この順番で結果を表示します.
            sequencialCities[i] = city;
        }

        // 誕生した年で昇順ソートします.
        cities = cities.OrderBy( x => x.Year ).ToArray();

        // 何番目に属するかを記憶します.
        var ParentIndex = new int[N];

        for(int i = 0; i < M; ++i)
        {
            var city = cities[i];

            ++ParentIndex[city.Parent - 1];

            city.InParentIndex = ParentIndex[city.Parent - 1];
        }

        // 結果表示を行います.
        for(int i = 0; i < M; ++i)
        {
            var city = sequencialCities[i];

            var index = city.InParentIndex;

            Console.WriteLine(
                city.Parent.ToString().PadLeft(6, '0')
                +
                index.ToString().PadLeft(6, '0')
            );
        }

#if DEBUG
        Console.ReadLine();
#endif
    }
}

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

int main(){
  int n,h,w;
  cin >> n >> h >> w;
  int ans=0;
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    if(a>=h&&b>=w) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int p[100005];
vector<int> G[100005];
vector<int> hv;
bool vis[100005];

void dfs(int v)
{
	vis[v] = true;
	hv.push_back(v);
	hv.push_back(p[v]);
	rep(i, G[v].size()) {
		int u = G[v][i];
		if(!vis[u]) dfs(u);
	}
}

int main()
{
	int n, m, ans = 0;
	scanf("%d%d", &n, &m);
	rep1(i, n) scanf("%d", &p[i]);
	rep1(i, m) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	rep1(i, n)
	if(!vis[i]) {
		hv.clear();
		dfs(i);
		sort(hv.begin(), hv.end());
		ans += hv.size();
		ans -= unique(hv.begin(), hv.end()) - hv.begin();
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 10360
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;

int main(void){
	const int N = 1299710;
	bool isP[N];
	rep(i, N) isP[i] = true;
	for(int i = 2; i * i < N; i ++) if(isP[i]) for(int j = i; i * j < N; j ++) isP[i * j] = false;

    for(int n, r, res; cin >> n, n; cout << res << endl){
        r = n;
        if(isP[n]) res = 0;
        else{
            while(!isP[--r]);
            while(!isP[++n]);
        }
        res = n - r;
    }

    return 0;
}

Measured memory_bytes: 2428
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
using namespace std;
int n,K;
int fac[100010],cnt;
int f[100010];
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int ans;
int main()
{
    cin>>n>>K;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac[++cnt]=i;
            if(n/i!=i)  fac[++cnt]=n/i;
        }
    }
    sort(fac+1,fac+cnt+1);
    for(int i=1;i<=cnt;i++)
    {
        f[i]=quick_pow(K,(fac[i]+1)/2);
        for(int j=1;j<i;j++)
        {
            if(fac[i]%fac[j]==0)  f[i]=(f[i]-f[j]+mod)%mod;
        }
        if(fac[i]&1)  ans=(ans+1ll*fac[i]*f[i]%mod)%mod;
        else          ans=(ans+1ll*(fac[i]>>1)*f[i]%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++) 

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A*N <= B) {
        cout << A*N << endl;
    } else cout << B << endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(void)
{
    int num;
    double w,h;
    while(~scanf("%d,%lf,%lf",&num,&w,&h)) {
        double bmi = w / h / h;
        if(bmi >= 25.0)
            printf("%d\n",num);
    }
    return 0;
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  ll res = n * (n - 1) / 2;
  cout << res << endl;
  return 0;
}

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

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


Measured memory_bytes: 3124
#include <stdio.h>
int main(void){
    int d,g,i,j,k;
    long long ans=100000;
    scanf("%d %d",&d,&g);
    int p[d],c[d];
    for(i=0;i<d;i++) scanf("%d %d",&p[i],&c[i]);
    for(i=0;i<(1<<d);i++){
        long long cnt=0,tmp=0;
        for(j=0;j<d;j++){
            if(i&(1<<j)){
                tmp += 100*p[j]*(j+1)+c[j];
                cnt += p[j];
            }
        }
        if(g<=tmp){
            if(cnt<ans) ans=cnt;
        }
        else{
            for(j=d-1;j>=0;j--){
                if(i&(1<<j)) continue;
                else{
                    for(k=0;k<p[j];k++){
                        if(tmp>=g) break;
                        tmp+=100*(j+1);
                        cnt++;
                    }
                }
            }
        }
        if(cnt<ans) ans=cnt;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1728