akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,h,w,d[4];
vi x,y,c;
vvp a,b;
vvi g;

void add(int u,int v){
	g[u].push_back(v);
	g[v].push_back(u);
}

void dfs(int v,vi e){
	c[v]=1;
	int X=x[v],Y=y[v];
	if(X==0&&!e[0]) e[0]++,d[0]++;
	if(X==h-1&&!e[1]) e[1]++,d[1]++;
	if(Y==0&&!e[2]) e[2]++,d[2]++;
	if(Y==w-1&&!e[3]) e[3]++,d[3]++;
	for(auto u:g[v]) if(!c[u]) dfs(u,e);
}

int main(){
	cin>>n>>h>>w;
	a=vvp(h);
	b=vvp(w);
	x=y=c=vi(n);
	g=vvi(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		x[i]--;y[i]--;
		a[x[i]].push_back({y[i],i});
		b[y[i]].push_back({x[i],i});
	}
	for(int i=0;i<h;i++){
		sort(a[i].begin(),a[i].end());
		for(int j=1;j<a[i].size();j++){
			int u=a[i][j-1].second,v=a[i][j].second;
			add(u,v);
		}
	}
	for(int i=0;i<w;i++){
		sort(b[i].begin(),b[i].end());
		for(int j=1;j<b[i].size();j++){
			int u=b[i][j-1].second,v=b[i][j].second;
			add(u,v);
		}
	}
	int t=0,M=0;
	for(int i=0;i<n;i++) if(!c[i]){
		vi e(4);
		dfs(i,e);
		t++;
	}
	for(int i=0;i<4;i++) M=max(M,d[i]);
	cout<<n-1+(t==1?0:t-M)<<endl;
}


Measured memory_bytes: 11836
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(A: int, P: int):
    return (3 * A + P) // 2


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    result = solve(A, P)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5756
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int fiveHandredYenCoins = sc.nextInt();
        int oneHandredYenCoins = sc.nextInt();
        int fiftyYenCoins = sc.nextInt();
        int sumYen = sc.nextInt();

        int count = 0;

        for(int a=0;a<=fiveHandredYenCoins;a++) {
            for(int b=0;b<=oneHandredYenCoins;b++) {
                for(int c=0;c<=fiftyYenCoins;c++) {
                    if((500 * a) + (100 * b) + (50 * c) == sumYen) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define LL long long

const int N = 2e5 + 5;
const int M = 2e5 + 5;

int n, cnt, first[N], dep[N] = { -1 },ans[N],cntt[2];

std::queue <int> q[3];

struct EDGE {
	int to, _next;
} e[M << 1];

void Add_Edge(int u, int v) {
	e[cnt].to = v;
	e[cnt]._next = first[u];
	first[u] = cnt++;
}

void dfs(int x, int p) {
	dep[x] = dep[p] + 1;
	for(int i = first[x], y = e[i].to; ~i; i = e[i]._next, y = e[i].to)
	if(y != p) dfs(y, x);
}

int main() {
	std::cin >> n;
	memset(first, -1, sizeof(first));
	for(int i = 1; i <= n - 1; ++i) {
		int u, v;
		std::cin >> u >> v;
		Add_Edge(u, v);
		Add_Edge(v, u);
	}
	dfs(1, 0);
	for(int i = 1; i <= n; ++i)
		q[i % 3].push(i),++cntt[dep[i]%2];
	if(std::min(cntt[0],cntt[1])<=n/3)
	{
		int k=cntt[0]>cntt[1];
		for(int i=1;i<=n;++i) if(dep[i]%2==k) {ans[i]=q[0].front();q[0].pop();continue;}
		for(int i=1;i<=n;++i)
			if(dep[i]%2!=k)
			{
				if(!q[0].empty()) {ans[i]=q[0].front();q[0].pop();continue;}
				if(!q[1].empty()) {ans[i]=q[1].front();q[1].pop();continue;}
				if(!q[2].empty()) {ans[i]=q[2].front();q[2].pop();continue;}
			}
	}
	else
		for(int i = 1; i <= n; ++i)
		{
			if(!q[dep[i]%2+1].empty()) ans[i]=q[dep[i]%2+1].front(),q[dep[i]%2+1].pop();
			else ans[i]=q[0].front(),q[0].pop();
		}
	for(int i = 1; i <= n; ++i) printf("%d ",ans[i]);
	return 0;
}

// ----------------------------
// by imzzy


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

int main()
{
  long N, M;

  cin >> N >> M;

  vector<int> vec(N);
  long sum = 0;

  for (int i = 0; i < N; i++)
  {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  bool ans = true;

  for (int i = 0; i < M; i++)
  {
    if (vec.at(i) * 4 * M < sum)
    {
      ans = false;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}


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

int main() {
  int N;
  cin >> N;
  int A[2][N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  int dp[2][N];
  dp[0][0] = A[0][0];
  dp[1][0] = A[0][0] + A[1][0];
  for (int i = 1; i < N; i++) {
    dp[0][i] = dp[0][i - 1] + A[0][i];
    dp[1][i] = max(dp[0][i], dp[1][i - 1]) + A[1][i];
  }
  cout << dp[1][N - 1];
}


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

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

    if (a > b) swap(a, b);
    if (a > c) swap(a, c);
    if (b > c) swap(b, c);

    cout << a << ' ' << b << ' ' << c << endl;

    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

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

  ll N, K;
  std::cin >> N >> K;

  std::vector<ll> va(N, 0LL);
  for (ll k = 0; k < K; k++) {
    ll D;
    std::cin >> D;
    for (ll i = 0; i < D; i++) {
      ll a;
      std::cin >> a;
      a--;
      va[a]++;
    }
  }

  ll sum = 0LL;
  for (auto& a : va) {
    if (a == 0LL) sum++;
  }

  print(sum);
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  vector<int> A(N,0);
  vector<int> Aout(N,0);

  A.at(0) = 0;
  for(int i=1; i < N ;i++){
    int tmp;
    cin >> tmp;
    Aout.at(tmp-1)++;
  }


  for(int i=0; i < N ;i++){
    cout  << Aout.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 4844
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 line = "";

		char[] octs;
		while (!(line = br.readLine()).equals("0")) {
			octs = Integer.toOctalString(Integer.parseInt(line)).toCharArray();
			for (int i = 0; i < octs.length; i++) {
				if (octs[i] == '4')
					octs[i] = '5';
				else if (octs[i] > '4')
					octs[i] = (char) ((int) octs[i] + 2);
			}
			System.out.println(String.valueOf(octs));
		}
	}
}

Measured memory_bytes: 31980
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

int main(){
  int n;cin >> n;
  string s,t;cin >> s >> t;
  int same=n;
  reverse(s.begin(),s.end());
  while(same>0){
  bool can=true;
  rep(i,same){
    if(s[same-i-1]!=t[i]){
      can=false;
      break;
    }
  }
  if(!can){
    same--;s.pop_back();t.pop_back();
  }
  if(can)break;
  }
  cout << 2*n-same << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll N, T, A, tT = 1, tA = 1;

int main() {
	rd(N);
	repi(i, 0, N) {
		cin >> T >> A;
		ll kT = (tT + T - 1) / T, kA = (tA + A - 1) / A;
		ll k = max(kT, kA);
		tT = T*k, tA = A*k;
	}
	wrln(tT + tA);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int K=1e6;
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  vb is_prime(K+1, true);
  is_prime[0]=false; is_prime[1]=false;
  for(int i=2; i*i<=K; i++) {
    if(!is_prime[i]) continue;
    for(int j=2; i*j<=K; j++) is_prime[i*j]=false;
  }
  vi prime;
  rep(i,1e3+1) {
    if(is_prime[i]) prime.push_back(i);
  }
  
  vi count(K+1);
  int siz=prime.size();
  rep(i,N) {
    rep(j,siz) {
      if(is_prime[A[i]]) {
        count[A[i]]++;
        break;
      }
      if(!(A[i]%prime[j])) {
        count[prime[j]]++;
        while(!(A[i]%prime[j])) A[i]/=prime[j];
      }
    }
  }
  
  int ans=2;
  rep(i,1e6+1) {
    if(count[i]>1) ans=1;
    if(count[i]==N) {
      ans=0;
      break;
    }
  }
  
  if(ans==0) cout << "not coprime" << endl;
  else if(ans==1) cout << "setwise coprime" << endl;
  else cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 11092
#include<stdio.h>
int main() {

	int n, k, a[200001], i, j = 0;


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

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

	for (i = k; i < n; i++) {
		if (a[j] < a[i])
			printf("Yes\n");
		else
			printf("No\n");
		j++;
	}
	
	return 0;
}

Measured memory_bytes: 2884
using System;
using System.Collections.Generic;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Trim();

            var maxV = 0;
            for(var i = 1; i < n; i++){
                var x = s.Substring(0, i);
                var y = s.Substring(i, n - i);

                var d = new Dictionary<char,int>();
                foreach(var c in x){
                    if(!d.ContainsKey(c)){
                        d.Add(c, 1);
                    }
                }
                foreach(var c in y){
                    if(d.ContainsKey(c)){
                        d[c] += 1;
                    }
                }

                var count = d.Where(t => t.Value >= 2).Count();
                maxV = Math.Max(maxV, count);
            }

            Console.WriteLine(maxV);
        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 200005
int n,a,b;
int main(){
		_io;
		
		cin>>n>>a>>b;
		cout<<min(b,(a*n));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;
  
  int year = (S[0] - '0') * 1000 + (S[1] - '0') * 100 + (S[2] - '0') * 10 + S[3] - '0';
  int month = (S[5] - '0') * 10 + S[6] - '0';

  string answer = "";

  if (2019 < year) {
    answer = "TBD";
  } else if (2019 == year && 4 <month ) {
    answer = "TBD";
  } else {
    answer = "Heisei";
  }
  
  cout << answer << endl;
 
}

Measured memory_bytes: 256
n = gets.to_i
array = gets.split(' ').map {|a| a.to_i }

flag = true
change_times = 0

0.upto(n-1) do |i|
    min_j = i
    i.upto(n-1) do |j|
        min_j = j if array[j] < array[min_j]
    end
    if i != min_j then
        array[i], array[min_j] = array[min_j], array[i]
        change_times = change_times + 1
    end
end

puts array.join(' ')
puts change_times

Measured memory_bytes: 8668
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+50;
typedef long long ll;
ll a[maxn];
void init()
{
	for(int i=2;i<=1e7;++i) a[i]=2;
	a[1]=1;
	for(int i=2;i<=5*1e6;++i)
	{
		for(int j=2;j*i<=1e7;++j)
		{
			a[i*j]++;
		}
	}
}
int main()
{
	init();
	int n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;++i) ans+=i*a[i];
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 81756
#include<iostream>

bool isleap( int y )
{
	return ( y % 4 == 0 && y % 100 != 0 ) || y % 400 == 0;
}

int calc( int y, int m, int d )
{
	int ret = 0;

	for( int i = 0; i <= y; ++i )
	{
		for( int j = 1; j <= ( i == y ? m : 12 ); ++j )
		{
			if( i == y && j == m )
				ret += d;
			else if( j == 2 )
				ret += 28 + isleap( i );
			else if( j == 4 || j == 6 || j == 9 || j == 11 )
				ret += 30;
			else
				ret += 31;
		}
	}

	return ret;
}

int main()
{
	int y[2], m[2], d[2];
	while( true )
	{
		for( int i = 0; i != 2; ++i )
			if( !( std::cin >> y[i] >> m[i] >> d[i] ) || y[i] < 0 || m[i] < 0 || d[i] < 0 )
				return 0;

		std::cout << calc( y[1], m[1], d[1] ) - calc( y[0], m[0], d[0] ) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
a,b,c,d,e,f = map(int,input().split())
can = []
for ai in range(31):
  for bi in range(31):
    if ai == bi == 0:
      continue
    whole = ( ai * a + bi * b ) * 100
    sugarmax = ( ai * a + bi * b ) * e
    sugarrest = sugarmax
    #f = juicemax
    juicerest = f - whole
    ci = 0
    while True:
      if juicerest < 0 or sugarrest < 0:
        break
      di = min( sugarrest , juicerest ) // d
      can.append([(ci*c+di*d)/(whole+di*d),whole+di*d,ci*c+di*d,ai,bi,ci,di,sugarrest,juicerest])
      whole += c
      sugarrest -= c
      juicerest -= c
      ci += 1
can.sort()
#print(can[-1])
print(str(can[-1][1]) + ' ' + str(can[-1][2]))

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int size = in.nextInt(), arr[] = new int[size];
		for(int i = 0; i < size; i++) {
			arr[i] = Integer.parseInt(in.next());
		}

		int loop = in.nextInt();
		for(int i = 0; i < loop; i++) {
			int begin = Integer.parseInt(in.next()), end = Integer.parseInt(in.next());
			for(int j = 0; j < (end - begin)/2; j++) {
				int temp = arr[begin + j];
				arr[begin + j] = arr[end - 1 - j];
				arr[end - 1 - j] = temp;
			}
		}

		for(int i = 0; i < size; i++) {
			out.printf("%d%s", arr[i], (i < size - 1) ? " " : "\n" );
		}
		out.flush();
		in.close();
	}
}



Measured memory_bytes: 38876
#include <bits/stdc++.h>
using namespace std;
int n,k,h[1000000],tas;
int main() {
    cin>>n>>k;
    for (int i=0;i<n;i++){
        cin>>h[i];
    }
    for (int i=0;i<n;i++){
        if (h[i]>=k) tas++;
    }
    cout<<tas;
}   

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (N[i] - '0' == 1)
            ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(usize, u32);
    let (s, ) = input!(String);

    let mut count = 0;
    let mut current_direction = ' ';

    for c in s.chars() {
        if current_direction == c {
            count += 1;
        } else {
            current_direction = c;
        }
    }

    let ans = std::cmp::min((n - 1) as u32, count + 2 * k);

    println!("{}", ans);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	VI s(n+1); s[0]=0;
	REP(i,n){
		s[i+1]=s[i]+a[i]-1+k;
		s[i+1]%=k;
	}
	map<ll,ll> mp;
	ll ans=0;
	REP(i,n+1){
		if(i>=k)
			mp[s[i-k]]--;
		ans+=mp[s[i]];
		mp[s[i]]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>
 
#define MAX 101
#define INF 10000000
#define NIL -1
 
#define WHITE 0
#define BLACK 1 
 
int n;
int G[MAX][MAX];
 
void prim(void);
 
int main(){
 
  int i, j, k, u, v, w;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){ 
    for(j = 0; j < n; j++){
      G[i][j] = INF; 
    } 
  }
 
  for(i = 0; i < n; i++){     
    scanf("%d %d", &u, &k); 
    for(j = 0; j < k; j++){ 
      scanf("%d %d", &v, &w);
      G[u][v] = w; 
    } 
  }
 
  prim();
 
  return 0; 
}


void prim(){
 
  int u, v, mincost, i, sum;
  int d[MAX];
  int pi[MAX];
  int color[MAX];
 
  sum = 0;
 
  for(u = 0; u < n; u++){
    d[u] = INF;   
    pi[u] = NIL;
    color[u] = WHITE;
  }
 
  d[0] = 0;
  
  while(1){
    mincost = INF;
    for(i = 0; i < n; i++){
      if((color[i] != BLACK) && (d[i] < mincost)){
    mincost = d[i];
    u = i;
      }
    }
 
    if(mincost == INF)
      break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(d[v] > d[u] + G[u][v]){
    d[v] = d[u] + G[u][v];
    pi[v] = u;
      }
    }
  }
 
  for(i = 0; i < n; i++)
    printf("%d %d\n", i, d[i]);
}

Measured memory_bytes: 640
def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs


def solve(x, y):
    d, m = divmod(x + y, 3)
    if m != 0 or x / y > 2 or y / x > 2:
        return 0
    c = abs(d - x)

    MOD = 10 ** 9 + 7
    f, invs = prepare(d, MOD)
    return f * invs[c] * invs[d - c] % MOD


x, y = map(int, input().split())
print(solve(x, y))


Measured memory_bytes: 29300
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, S = lr()
A = lr()
dp = np.zeros(S+1, np.int64)
answer = 0
for a in A:
    dp[0] += 1 # Lの数は１個ずつ加わる
    prev = dp.copy()
    dp[a:] += prev[:-a]
    dp %= MOD
    answer += dp[-1] # その位置をRとした時

print(answer % MOD)
# 26


Measured memory_bytes: 17964
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    count = 1
    count *= bisect.bisect_left(A,b)
    count *= n-bisect.bisect_right(C,b)
    ans += count

print(ans)

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

/**
 * Created by fcdkbear on 15.10.16.
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String s = in.next();
        int count = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s.charAt(i) == 'p') {
                count++;
            }
        }
        int canUse = s.length() / 2;
        out.println(canUse - count);
        out.close();
    }

    static class Pair {
        private long first;
        private int second;

        public Pair(long first, int second) {
            this.first = first;
            this.second = second;
        }

        public long getFirst() {
            return first;
        }

        public void setFirst(long first) {
            this.first = first;
        }

        public int getSecond() {
            return second;
        }

        public void setSecond(int second) {
            this.second = second;
        }
    }

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

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

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

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

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

    }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
ll cnt[10][10];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;

	rep(i, 1, N + 1) {
		int btm = i % 10;

		int top = -1, x = i;
		while (0 < x) {
			top = x % 10;
			x /= 10;
		}

		cnt[top][btm]++;
	}

	ll ans = 0;
	rep(Atop, 0, 10) rep(Abtm, 0, 10) ans += cnt[Atop][Abtm] * cnt[Abtm][Atop];
	cout << ans << endl;
}







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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for(int i = 0;i < m;i++){
        cin >> l[i] >> r[i];
    }
    int minNumber = l[0];
    int maxNumber = r[0];
    for(int i = 1;i < m;i++){
        minNumber = max(l[i], minNumber);
        maxNumber = min(r[i], maxNumber);
    }
    if(n > maxNumber){
        n = maxNumber;
    }
    if(n < minNumber){
        n = 0;
    }else{
        n = n - minNumber + 1;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int n, p, temp;
map<int, int> mp;
int a, cnt;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> temp;
		mp[temp] = temp;
	}
	cin >> p;
	for (int i = 0; i < p; ++i){
		cin >> a;
		if (mp[a] == a) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 10136
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math;

void main()
{
    stdin.byLine().map!(to!real).map!(v=>cast(int)(ceil((v/9.8)*(v/9.8)*4.9/5))+1).map!(to!string).join("\n").writeln();
}

Measured memory_bytes: 1092
#include "stdio.h"
#include <iostream>
#include <algorithm>

using namespace std;

long long int gten[1111111];
long long int p[1111];

long long int ans[1000];

int main()
{
  int ww = 0;
  while(1)
    {
      long long int n,m;
      scanf("%lld %lld",&n,&m);
      if(n == 0 && m == 0)
	{
	  break;
	}
      p[0] = 0;
      for(int i = 1; i <= n; i++)
	{
	  scanf("%lld",&(p[i]));
	}
      int nw = 0;
      for(int i = 0; i <= n; i++)
	{
	  for(int ii = 0; ii <= n; ii++)
	    {
	      gten[nw] = p[i] + p[ii];
	      nw++;
	    }
	}
      sort(gten,gten + nw);
      long long int max = 0;
      int ai = 0;
      for(int i = nw - 1; i >= 0; i--)
	{
	  while(1)
	    {
	      if(ai + 1 >= nw)
		{
		  break;
		}
	      if(gten[i] + gten[ai + 1] <= m)
		{
		  ai++;
		  if(max < gten[i] + gten[ai])
		    {
		      max = gten[i] + gten[ai];
		    }
		}
	      else
		{
		  break;
		}
	    }
	}
      ans[ww] = max;
      ww++;
    }
  for(int i = 0; i < ww; i++)
    {
      printf("%lld\n",ans[i]);
    }
  return 0;
}

Measured memory_bytes: 9384
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int w, h, n, x, y, a;
   cin >> w >> h >> n;
   int x_max=w;
   int x_min=0;
   int y_max=h;
   int y_min=0;
   for(int i=0;i<n;i++) {
     cin >> x >> y >> a;
     if ((a==2) && (x_max > x)) x_max=x;
     if ((a==1) && (x_min < x)) x_min=x;
     if ((a==4) && (y_max > y)) y_max=y;
     if ((a==3) && (y_min < y)) y_min=y;
   }
   if ((x_max < x_min) || (y_max < y_min)) cout << 0 << endl;
   else cout << (x_max - x_min) * (y_max - y_min) << endl;
}

Measured memory_bytes: 3584
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
Y = []
for i in range(n):
  Y.append(x[i+1]-x[i])

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

ans = Y[0]
for y in Y:
  ans = gcd(ans,y)
print(ans)

Measured memory_bytes: 15020
n = int( input() )
a = []

max_a = 0
for i in (range( n )) :
  temp = int( input())
  if temp > max_a : max_a = temp
  a.append( temp )
a_copy = a

max_index = a.index( max_a )
a_copy.pop( max_index )
max_a2 = max( a_copy )

for i in range( n ) :
  if i != max_index : print( max_a )
  else              : print( max_a2 )


Measured memory_bytes: 12640
#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <locale>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <list>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
string s;
int main()
{
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A' && s[i+1]=='C')
        {cout<<"Yes";return 0;}
    }
    cout<<"No";
    return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int d, c;
	ll ans = 1, m = pow(10, 9) + 7;
	
	cin >> d >> c;
	if(abs(d-c) > 1) cout << 0;
	else{
		int m1 = max(d, c);
		int m2 = min(d, c);
		REP(i, 0, m2){
			ans *=  (m1-i);
			ans %= m;
			ans *=  (m2-i);
			ans %= m;
		}
		if(d == c) ans*=2;
		cout << ans%m;
	}
	
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define LL long long

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

    vector<int> l(m);
    vector<int> r(m);
    for(int i = 0; i < m; i++) cin >> l[i] >> r[i];

    sort(l.begin(),l.end(),greater<int>());
    sort(r.begin(),r.end());
    
    //cerr << r[0] << l[0] << endl;

    int ans = (r[0] - l[0]) + 1;
    if (ans > n) {
        ans = n;
    } else if (ans < 0) {
        ans = 0;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

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

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

int main()
{
	//fastIOS();

	int x;
	scanf("%d", &x);

	if (x >= 1200)
		printf("ARC\n");
	else
		printf("ABC\n");
}

Measured memory_bytes: 256
/**   
 *   Author:    @glaucoacassioc
 *   Created on 11.09.2020, 16:56:16
**/
#include <bits/stdc++.h>

using namespace std;
  
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, item_popular, sum = 0, cont = 0;
 
	cin >> n >> m;
	vector<int> v(n);
	for(int i=0; i < n; i++)
	{
		cin >> v[i];
		sum+= v[i];
	}
 
	item_popular = 4 * m;
	bool popular = false;
	for(int i=0; i<n; i++)
	{
		//Quer saber se um item eh popular, so eh popular se for menor que 1/4*m do total de votos.
		//Soma os votos pra saber qual eh o total de votos  v[i] * 1 * 4 * m;
		if(v[i] * 1LL * item_popular >= sum) cont++;
		if(cont == m)
		{ 
			popular = true;
			break;
		}
	}
	popular ? cout << "Yes\n" : cout << "No\n";
	return 0;
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int m[6];
char p[101];

class Dice {
    public:
    int x, y, z;
    Dice() : x(3), y(1), z(2) {}
    ~Dice() {}
    void S() {
        int z_ = z;
        z = y;
        y = 7-z_;
    }
    void N() {
        int y_ = y;
        y = z;
        z = 7-y_;
    }
    void W() {
        int y_ = y;
        y = x;
        x = 7-y_;
    }
    void E() {
        int x_ = x;
        x = y;
        y = 7-x_;
    }
    void p() {
        cout<<x<<' '<<y<<' '<<z<<endl;
    }
};

Dice d;

int main(){
	cin.tie(0);
	
	rep(i, 6)cin>>m[i];
	cin>>p;
	
	for(int i=0;p[i]!='\0';i++) {
	    switch(p[i]) {
	        case 'S':
	        d.S();
	        break;
	        case 'N':
	        d.N();
	        break;
	        case 'W':
	        d.W();
	        break;
	        case 'E':
	        d.E();
	        break;
	    }
	}
	
	cout<<m[d.y-1]<<endl;
	
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
#define P pair<int,int>


int main()
{
    int N,W;
    cin >> N >> W;
    vi w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    
    int w0 = w[0]-1;
    rep(i,N) w[i]-=w0;
    
    
    ve<ve<ve<int>>> dp(N+1,ve<ve<int>>(400,ve<int>(101,0)));
    
    rep(i,N) rep(j,400) rep(k,100){
        if(w[i] <= j){
            if(dp[i][j][k+1] < dp[i][j-w[i]][k]+v[i]){
                dp[i+1][j][k+1] = dp[i][j-w[i]][k]+v[i];
            }else{
                dp[i+1][j][k+1] = dp[i][j][k+1];
            }
        }else{
            dp[i+1][j][k+1] = dp[i][j][k+1];
        }
    }
    
    

    ll ans = 0;
    rep(j,400) rep(k,101){
        ll a = (ll)j + (ll)k*w0;
        if(a <= (ll)W) ans = max(ans,(ll)dp[N][j][k]);
    }
    out(ans);

    return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
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 A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  int ans = 0;
  rep(i, 1, n + 1) ans += i * sowa(n / i);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <cmath>
#include <iomanip>
#include <iostream>

double rad(double& angle) { return angle / 180 * M_PI; }
double cosine(double& a, double& b, double& rad) {
  return sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(rad));
}
double area(double& a, double& b, double& rad) { return a * b * sin(rad) / 2; }
double circumference(double& a, double& b, double& rad) {
  return a + b + cosine(a, b, rad);
}
double height(double& a, double& b, double& rad) { return b * sin(rad); }

int main() {
  double a, b, angle;
  std::cin >> a >> b >> angle;
  double theta = rad(angle);
  std::cout << std::fixed << std::setprecision(5);
  std::cout << area(a, b, theta) << std::endl;
  std::cout << circumference(a, b, theta) << std::endl;
  std::cout << height(a, b, theta) << std::endl;
  return 0;
}



Measured memory_bytes: 3436
def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret


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

if A == warshall_floyd(A):
    ans = 0
    for i in range(1, N):
        for j in range(0, i):
            if min([A[i][k] + A[k][j] - A[i][j] for k in range(N) if k != i and k != j] + [1]) > 0:
                ans += A[i][j]
    print(ans)
else:
    print(-1)


Measured memory_bytes: 56668
N = int(input())
a = [int(i) for i in input().split()]
a_sorted = sorted(a,reverse=True)
diff = 0
for i in range(int(N/2)):
       diff +=  a_sorted[2*i] - a_sorted[2*i + 1]
if(N%2 != 0):
       diff += a_sorted[N-1]
print(diff)
               


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int N, M;
vector<int> a, b;
vector<vector<int> > connect;
vector<bool> isVisited;
long long ans;

void dfs(int curr) {
    bool all = true;
    REP (i, N) {
        if (!isVisited[i])
            all = false;
    }
    if (all) {
        ans++;
    }

    for (auto next : connect[curr]) {
        if (isVisited[next])
            continue;
        isVisited[next] = true;
        dfs(next);
        isVisited[next] = false;
    }
}

int main()
{
    cin >> N >> M;
    a.resize(M);
    b.resize(M);
    connect = vector<vector<int> >(N, vector<int>());
    REP (i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        connect[a[i]].push_back(b[i]);
        connect[b[i]].push_back(a[i]);
    }

    isVisited = vector<bool>(N, false);
    isVisited[0] = true;
    dfs(0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    vector<int>A(n);
    rep(i,n)cin>>A[i];
    int Ans[n+1];
    int res;int x=0;
    for(int i=n;i>=1;i--){
        res=0;
        for(int j=2;i*j<=n;j++){
            res+=Ans[j*i];
        }
        //cout<<res<<endl;
        Ans[i]=((A[i-1]-res)%2+2)%2;
        //cout<<Ans[i]<<endl;
        if(Ans[i]==1)x++;
    }
    cout<<x<<endl;
    rep(i,n){
        if(Ans[i+1]==1)cout<<i+1<<' ';
    }
}



Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector< pair<int, int> > v(N);

	for (int i = 0; i < N; ++i) {
		int a,b;
		cin >> a >> b;

		v[i] = pair<int, int>(a,b);
	}

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


	long long k = 0;
	for (int i = 0; i < N; ++i) {
		k += v[i].second;
		if (k >= K) {
			cout << v[i].first << endl;
			break;
		}
	}
 
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;


int main(){
    // あとで消す
    //std::ifstream in("bin4.txt");
    //std::cin.rdbuf(in.rdbuf());

    int H,N;
    cin >> H >> N;
    int sum = 0;
    int A;

    for(size_t i=0;i<N;i++){
        cin >> A;
        sum += A;
    }

    if(sum>=H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        if (s.Length == 3)
        {
            s = string.Join("", s.Reverse());
        }

        string answer = s;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 26584
#include <iostream>

int main() {
  int n, m, x;
  std::cin >> n >> m >> x;
  int A[110];
  for(int i=0; i<110; ++i) {
    A[i] = 0;
  }

  for(int i=0; i<m; ++i) {
    int index;
    std::cin >> index;
    A[index] += 1;
  }

  int left_sum = 0;
  int right_sum = 0;

  for(int i=0; i<n; ++i) {
    if(i < x) {
      left_sum += A[i];
    } else if(i > x) {
      right_sum += A[i];
    }
  }

  int min_ = std::min(left_sum, right_sum);
  std::cout << min_ << std::endl;
}

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

typedef long long ll;
const int N = 1e5 + 5;

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    int ra = a+W, rb = b+W;
    if ((b >= a && b <= ra) || (rb >= a && rb <= ra)) cout << 0 << '\n';
    else if (ra <= b) cout << b-ra << '\n';
    else if (rb <= a) cout << a-rb << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {

int n;
cin>>n;
while(1){
int a[4]={0};
int b[4]={0};
for(int i=0;i<4;i++) cin>>a[i];
int sum=10*a[0]+50*a[1]+100*a[2]+500*a[3];
int ot=sum-n;
b[3]=ot/500;
ot=ot%500;
b[2]=ot/100;
ot=ot%100;
b[1]=ot/50;
ot=ot%50;
b[0]=ot/10;
//cout<<"a";
//or(int i=0;i<4;i++) cout<<a[i]<<" "; 
//for(int i=0;i<4;i++) cout<<b[i]<<" ";
//cout<<endl;
if(a[0]>b[0]) cout<<"10"<<" "<<a[0]-b[0]<<endl;
if(a[1]>b[1]) cout<<"50"<<" "<<a[1]-b[1]<<endl;
if(a[2]>b[2]) cout<<"100"<<" "<<a[2]-b[2]<<endl;
if(a[3]>b[3]) cout<<"500"<<" "<<a[3]-b[3]<<endl;
cin>>n;
if(n==0) break;
cout<<endl;

}


	return 0;
 
   }

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <atcoder/all>
#include <cstdio>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

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

    scc_graph g(n);

    rep(i,m){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g.add_edge(u, v);
        g.add_edge(v, u);
    }

    auto scc = g.scc();

    if(int(scc.size()) == 0) cout << int(scc.size()) << endl;
    else cout << int(scc.size())-1 << endl;

    return 0;
}

Measured memory_bytes: 11192