akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n; i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		selection_sort(arr);
	}
	
	public static void selection_sort(int[] arr){
		int ans = 0;
		for(int i=0; i<arr.length; i++){
			int min_ix = i;
			for(int j=i; j<arr.length; j++){
				if(arr[min_ix] > arr[j]) min_ix = j;
			}
			if(min_ix != i){
				// swap
				int tmp = arr[min_ix];
				arr[min_ix] = arr[i];
				arr[i] = tmp;
				ans++;
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}


}



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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

    ll d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << '\n';
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n;

int main() {
	cin >> n;
	
	int ans = 1;
	while (ans*2<=n) ans *= 2;
	cout << ans << ln;
}

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

typedef long long int64;

using namespace std;

struct WeightedEdge {
  int from, to;
  int64 weight;
};

vector<vector<WeightedEdge>> ReadDirectedWeightedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<WeightedEdge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    int64 weight;
    cin >> v1 >> v2 >> weight;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(WeightedEdge({v1, v2, weight}));
  }
  return graph;
}

tuple<vector<int64>, vector<int>>
ShortestPathDijkstra(vector<vector<WeightedEdge>>& graph, int s) {
  int n = graph.size();
  vector<int64> distances(n, INT64_MAX);
  vector<int> parents(n, -1);
  struct State {
    int v, parent;
    int64 weight;
  };
  auto compare_state = [](State s1, State s2) {
    return s1.weight > s2.weight;
  };
  priority_queue<State, vector<State>, decltype(compare_state)>
  pq(compare_state);

  pq.push(State({s, -1, 0}));
  vector<int> visited(n);
  while(!pq.empty()) {
    State s = pq.top();
    pq.pop();
    if (visited[s.v]) continue;
    visited[s.v] = true;
    distances[s.v] = s.weight;
    parents[s.v] = s.parent;
    for (const auto& e : graph[s.v]) {
      if (visited[e.to]) continue;
      State next = State({e.to, s.v, s.weight + e.weight});
      pq.push(next);
    }
  }
  return make_tuple(distances, parents);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int v, e, r;
  cin >> v >> e >> r;
  auto graph = ReadDirectedWeightedGraph(v, e);
  vector<int64> distances;
  tie(distances, ignore) = ShortestPathDijkstra(graph, r);
  for (int64 distance : distances) {
    if (distance == INT64_MAX) {
      cout << "INF" << endl;
    } else {
      cout << distance << endl;
    }
  }
}



Measured memory_bytes: 22136
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    ans = n * (n + 1) ** 2 // 2 - n * (n + 1) * (2 * n + 1) // 6
    for _ in range(n-1):
        u, v = nm()
        if u > v:
            u, v = v, u
        ans -= u * (n - v + 1)
    print(ans)
    return

solve()


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<char> vec(H * W);
  
  for (int i = 0;i < H * W;i++) {
    cin >> vec.at(i);
  }
  
  for (int i = 0;i < W + 2;i++) {
    cout << "#";
  }
  
  cout << endl;
  
  for (int i = 0;i < H;i++) {
    cout << "#";
    for (int j = 0;j < W;j++) {
      cout << vec.at(W * i + j);
    }
    cout << "#" << endl;
  }
  
  for (int i = 0;i < W + 2;i++) {
    cout << "#";
  }
  
  cout << endl;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] arg)throws IOException{
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 //br.readline(); = 入力された１行分を日本語変換して返してくれる。
		 String str = br.readLine();

		 /*配列の型(intとかStringとか) [] 配列名 = 配列を用意
		  *今回はstrAryって配列にstrを入れてる。
		  *str.split = splitってのはString内に用意されてるメソッド
		  *文字列を分割するときに使用。今回は空白で区切ってって仕様なので
		  *split(" ")としてます。*/
		 String[] strAry = str.split(" ");

		 /*おなじみの文字列から数値への変換。
		  *ただし今回は指定先が配列の何番って風になってる。*/
		 int a = Integer.parseInt(strAry[0]);
		 int b = Integer.parseInt(strAry[1]);
		 int c = Integer.parseInt(strAry[2]);

		 //今回は昇順用のメソッドを呼び出しています。
		 Arrays.sort(strAry);

		 //表示は並び替えた３つの数値を配列の順番に表示。
		 System.out.println(strAry[0] + " " +strAry[1] + " " +strAry[2]);
	}
}

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

int main(){
	int n;
	cin >> n;
	int y = 100000;
	for(int i = 0 ; i < n ; i++){
		y = y * 105 / 100;
		if( y % 1000 ) y += 1000 - y % 1000;
	}
	cout << y << endl;
}

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

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

    int f[110][15], p[110][15];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    int res = -(1 << 30);
    for (int b = 1; b < (1 << 10); b++) {
        int cc = 0;
        for (int i = 0; i < n; i++) {
            int c = 0;
            for (int j = 0; j < 10; j++) {
                if ((b >> j & 1) && f[i][j]) c++;
            }
            cc += p[i][c];
        }
        if (res < cc) res = cc;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, m, k;
ll work(int n, int m) {
	ll ans = 0;
	for (int i = 0; i <= n - 2; i++)
	for (int j = 1; j <= m - 1 && i * j <= 2 * k + m; j++) {
		int tmp = 2 * k + __gcd(i, m) - i * j - 2;
		if (tmp >= 0) {
			int limit = min(n - 1 - i, tmp / m + 1);
			ans += (limit - (m * limit - __gcd(limit, j) - __gcd(limit + i, m - j) > tmp)) * (1 + (i != 0));
		}
	}
	return ans;
}
int main() {
	read(n), read(m), read(k);
	cout << work(n, m) * 2 + work(m, n) * 2 << endl;
	return 0;
}


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

int main(){
	int N, absmax = 0;
	cin >> N;
	cout << 2*N-1 << endl;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
		if(abs(A[absmax]) < abs(A[i])) absmax = i;
	}
	for(int i=0; i<N; i++) cout << absmax + 1 << " " << i + 1 << endl;
	if(A[absmax] < 0){
		for(int i=N; i>1; i--) cout << i << " " << i - 1 << endl;
	}else{
		for(int i=0; i<N-1; i++) cout << i + 1 << " " << i + 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef unsigned int uint;
typedef long long ll;
//typedef __int128 lll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> p(n);
    fori(n)
        cin>>p[i];

    int ans=0;
    for(int i=1; i<n-1; i++) 
        if((p[i-1]>p[i] && p[i+1]<p[i]) || (p[i-1]<p[i] && p[i+1]>p[i]))
            ans++;
        

    cout<<ans<<endl;

}



Measured memory_bytes: 256
N = int(input())
chk = [0] * (10 ** 4 + 2)
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            a = i**2 + j**2 + k**2 + i*j + j*k + i*k
            if a > 10001:
                break
            chk[a] += 1
for i in range(N):
    print(chk[i+1])

Measured memory_bytes: 9200
let m_1e9 = int_of_float 1e9 + 7
let ( *^ ) x y = ((x mod m_1e9) * (y mod m_1e9)) mod m_1e9
let split_string ?(pattern=" ") = Str.split @@ Str.regexp pattern

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string |> List.map int_of_string

let rec loop ans arr = function
  | [] -> Printf.printf "%d\n" @@ ans
  | x :: xs -> 
      let t = Array.fold_left (fun s i -> s + if i = x then 1 else 0) 0 arr in
      let i = if arr.(0) = x then 0 else if arr.(1) = x then 1 else 2 in
      arr.(i) <- arr.(i) + 1;
      loop (ans *^ t) arr xs

let () = loop 1 (Array.make 3 0) a

Measured memory_bytes: 13696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		sc.close();
		
		int numOfOdd = 0;
		if(n %2 == 1) {
			numOfOdd = n / 2 + 1;
		}else {
			numOfOdd =  n / 2;
		}
		
		System.out.println((double)numOfOdd / n);
	}
}

Measured memory_bytes: 21840
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long A, long long B, long long C){
  if ((A==B) && (B==C)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

int main(){
  long long C;
  long long B;
  long long A;
  scanf("%lld",&A);
  scanf("%lld",&B);
  scanf("%lld",&C);
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
def is_kai(s):
    for i in range(int((len(s))/2)):
        if s[i] != s[-i-1]:
            return False
    return True
if is_kai(s) and is_kai(s[:int((n-1)/2)]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
#include <queue>
#include <utility>

using namespace std;

void get_next(const string & pattern, int next[]);

int main()
{
    //method 1, time limit expired
    // string text, pattern;

    // cin >> text >> pattern;

    // int next[10001];
    // get_next(pattern, next);

    // int i = 0, j = 0, tlen = text.size(), plen = pattern.size();
    // while (true)
    // {
    //     while (i < tlen && j < plen)
    //     {
    //         if (j == -1 || text[i] == pattern[j])
    //         {
    //             ++i;
    //             ++j;
    //         }
    //         else
    //             j = next[j];
    //     }

    //     if (j == plen)
    //         cout << i - j << endl;
        
    //     if (i == tlen)
    //         break;

    //     //reset i and j
    //     i = i-j+1;
    //     j = 0;
    // } 


    //method 2
    string text, pattern;

    cin >> text >> pattern;   

    unsigned long long i = 0, pos;
    while (true)  
    {
        pos = text.find(pattern, i);
        if (pos != string::npos)
        {
            cout << pos << endl;  
            i = pos + 1;
        }
        else
            break;
    }

}



void get_next(const string & pattern, int next[])
{
    int i = 0, j = -1;
    next[0] = -1;
    while (i < pattern.size()-1)
    {
        if (j == -1 || pattern[i] == pattern[j])
        {
            ++i;
            ++j;
            if (pattern[i] != pattern[j])
                next[i] = j;
            else
                next[i] = next[j];
        }
        else
        {
            j = next[j];
        }
        
    }

}




Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[1234567], aa[12345678];
signed main() {
	int n, a, b, cnt = 0, zentai = 0, saigo = 0, ans = 0; double sum = 0; cin >> n >> a >> b;
	for (int h = 0; h < n; h++) { cin >> test[h]; }
	sort(test, test + n); reverse(test, test + n);
	for (int h = 0; h < a; h++) { sum += test[h]; }
	sum /= a; printf("%.10f\n", sum); saigo = test[a - 1];
	for (int h = 0; h < n; h++) { if (test[h] == saigo) { zentai++; } }
	for (int h = 0; h < a; h++) { if (test[h] == saigo) { cnt++; } }
	int z = 1;
	for (int h = 1; h <= cnt; h++) {
		z *= zentai - h + 1; z /= h;
	}
	if (sum != test[a - 1]) {
		cout << z << endl; return 0;
	}
	for (int h = a - 1; h < b; h++) {
		cnt++;
		if (test[h] == saigo) {
			ans += z; z *= zentai - cnt + 1; z /= cnt;
			//cout << z << ' ' << ans << endl;
		}
		else { break; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
// 髙橋君とホテルイージー
#include <iostream>
using namespace std;
int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<=k) cout<<n*x<<endl;
    else cout<<k*x+(n-k)*y<<endl;
    return 0;
}

Measured memory_bytes: 256
program Limited_Insertion
    implicit none
    integer(4):: n, i, tar, ai
    integer(4), allocatable:: b(:), a(:)

    read*, n
    allocate(b(n), a(n))

    read*, b(:)
    ai=0

    do while (ai < n)
        tar = 0
        do i=1, n
            if (b(i) == i) tar = i
        end do

        if (tar == 0) then
            print*, -1
            stop
        end if

        ai=ai+1
        a(ai) = tar
        b(tar:n-1) = b(tar+1:n)
        b(n) = 0
    end do

    do i=n,1,-1
        print*, a(i)
    end do
end program Limited_Insertion

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 xx, aa;
	cin >> xx >> aa;
	cout << (xx < aa ? 0 : 10) << endl;
	return 0;
}

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

#define NIL -1
#define INF 1000000001

using namespace std;

int fib(int n,vector<int> &fib_array){
     if(n == 0 || n == 1) {
         fib_array[n] = 1;
         return 1;
     }
     else {
         if(fib_array[n-2] == 0) fib_array[n-2] = fib(n-2,fib_array);
         if(fib_array[n-1] == 0) fib_array[n-1] = fib(n-1,fib_array);
         return fib_array[n-1] + fib_array[n-2];
     }
}

int main(){
    int n;
    scanf("%d",&n);
    vector<int> fib_array(n,0);
    printf("%d\n",fib(n,fib_array));
    return 0;
}


Measured memory_bytes: 3216
#include <stdio.h>

int main(void){
	int i, j, k, n, a[100], tmp;
	scanf("%d",&n);
	for(i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for(i = 0;i < n;i++){
		printf("%d",a[i]);
		if(i != n - 1) printf(" ");
	}
	printf("\n");
	for(i = 1;i < n;i++){
		tmp = a[i];
		for(j = i - 1;j >= 0 && a[j] > tmp;j--)
				a[j + 1] = a[j];
		a[j + 1] = tmp;
		for(j = 0;j < n;j++){
			printf("%d",a[j]);
			if(j != n - 1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
  int N, A, B, cnt=0;
  cin >> N >> A >> B;
  for(int i=1; i<=N; i++){
    if(A<=i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10 && i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10<=B){
      cnt+=i;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

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

    if(a>=b)
        cout<<"delicious";

    else if((a+x+1)>b)
        cout<<"safe";

    else
        cout<<"dangerous";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n, m;
V< V<int> > edges;
V<int> dist;
V<bool> visited;

int dfs(int i) {
    if (visited[i]) return dist[i];
    visited[i] = true;
    for (int e: edges[i]) {
        chmax(dist[i], dfs(e) + 1);
    }
    return dist[i];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    edges.resize(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--, y--;
        edges[x].emplace_back(y);
    }
    dist.resize(n), visited.resize(n, false);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) chmax(ans, dfs(i));
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a = N;
  int b = 0;
  while(a > 0){
    b += a % 10;
    a/=10;
  }
  if(N % b == 0) cout << "Yes" << endl;
  else cout << "No" <<endl;
}

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

int main(void){
  int s,w;
  cin >> s >> w;

  if(w>=s){
    cout << "unsafe" << endl;
  }
  else{
    cout << "safe" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
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;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define push_back pb

const int mod = 1000000007;

int n, m;
vi a, b;
vb v; //訪問済みかどうかのチェック

int dfs(int i, int k){
    // i : 探索数, k : 今の頂点
    if(v.at(k)){return 0;}
    if(i == n){return 1;}

    v.at(k) = true;

    int cnt = 0;

    rep(j, 0, m){
        if(a.at(j)==k){cnt += dfs(i + 1, b.at(j));}
        if(b.at(j)==k){cnt += dfs(i + 1, a.at(j));}
    }

    v.at(k) = false;

    return cnt;
}

int main(){
    cin >> n >> m;
    a.resize(m);
    b.resize(m);
    v.assign(n, false);
    rep(i, 0, m){cin >> a.at(i) >> b.at(i);a.at(i)--;b.at(i)--;}
    cout << dfs(1, 0);
}
    

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A;
vector<ll> ans;

// 整数 n の約数をすべて vector に格納する
// 量的には大体 10^9 で 100 個の約数がある
// 計算量 O(√n)
vector<int> GetDivisor(int n) {
    vector<int> v;
    for(int i = 1; i*i <= n; ++i) {
        if(n % i == 0) {
            v.push_back(i);
            if(i != n / i) { v.push_back(n / i); }
        }
    }
    sort(v.begin(), v.end());
    return v;
}

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

    cin >> N;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
    }
    ans.assign(N, 0);

    int border = N / 2;
    if(N % 2 != 0) { border++; }
    for(int i = N - 1; i >= 0; --i) {
        if(i > border) {
            ans[i] = A[i];
        }
        else {
            if(ans[i] != A[i]) {
                ans[i] = 1;
            }
            else {
                ans[i] = 0;
            }
        }

        vector<int> res = GetDivisor(i+1);
        for(auto& r : res) {
            if(r == i + 1) { continue; }
            int ind = r - 1;
            ans[ind] += ans[i];
            ans[ind] %= 2;
        }
    }

    vector<int> disp;
    REP(i, N) {
        if(ans[i] == 1) {
            disp.push_back(i + 1);
        }
    }
    printf("%zu\n", disp.size());
    REP(i, disp.size()) {
        printf("%lld%c", disp[i], (i == disp.size()-1) ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 5108
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, W;
  ll dp[SIZE] = {};

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

  for(int i=0;i<n;i++){
    int w, v;
    scanf("%d%d", &w, &v);

    for(int j=W-w;j>=0;j--){
      dp[j+w] = max(dp[j+w], dp[j]+v);
    }
  }

  ll ans = 0;

  for(int i=0;i<=W;i++){
    ans = max(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
def run():
  S1 = list('-'+input())
  len_S1 = len(S1)
  S2 = list('-'+input())
  len_S2 = len(S2)
  dp = [[0] * (len_S2) for _ in range(len_S1)]
  #set dp[0][n], dp[n][0]
  for i1 in range(len_S1):
    if S2[0] == S1[i1]: gap = 0
    else: gap = 1
    dp[i1][0] = dp[i1-1][0] + gap
  for i2 in range(len_S2):
    if S1[0] == S2[i2]: gap = 0
    else: gap = 1
    dp[0][i2] = dp[0][i2-1] + gap
  #dp
  for i1 in range(1, len_S1):
    for i2 in range(1, len_S2):
      if S1[i1] == S2[i2]: gap = 0
      else: gap = 1
      dp[i1][i2] = min(dp[i1][i2-1]+1, dp[i1-1][i2]+1,
                       dp[i1-1][i2-1]+gap)
  print(dp[-1][-1])
    
if __name__ == '__main__':
    run()


Measured memory_bytes: 43080
a = int(input())
n = list(map(int, input().split()))
b=sorted(n,reverse=True)
ans=0
for i,j in enumerate (b):
    if i < a-1:
        ans += j*((1/2)**(i+1))
    if i ==a-1:
        ans += j*((1/2)**(i))
print(ans)

Measured memory_bytes: 3064
N, C = map(int,input().split())
X = []
V = []
for _ in range(N):
    x, v = map(int,input().split())
    X.append(x)
    V.append(v)

A = V[:]
B = V[::-1]

for i in range(N-1):
    A[i+1] += A[i]
    B[i+1] += B[i]

P = [0]
Q = [0]

for i in range(N):
    P.append(max(P[-1], A[i] - X[i] * 2))
    Q.append(max(Q[-1], B[i] - (C - X[N-i-1]) * 2))

ans = 0

for i in range(N):
    ans = max(ans, A[i] + Q[N-i-1] - X[i])
    ans = max(ans, B[i] + P[N-i-1]- (C - X[N-i-1]))

print(ans)

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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while (t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.ff << " -> " << x.ss << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;

	ll a; ld b;
    cin >> a >> b;
    
    ll nb = (b+0.005)*100;
    cout << a * nb / 100 << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int MAX = 2e5 + 5;


int32_t main()
{
   IOS;
   int n, m,k,books=0;
   cin >> n >> m >> k;

   int pn[MAX], pm[MAX];

   int N[MAX], M[MAX];

   for(int i=0; i<n; i++)
   {
   		cin >> N[i];
   		pn[i+1]=pn[i]+N[i];
   }
   		

   for(int i=0; i<m; i++)
   {
   		cin >> M[i];
   		pm[i+1]=pm[i]+M[i];
   }

   int j=m;

   for(int i=0; i<=n; i++)
   {
   		if(pn[i]>k)
   			break;
   		while(pm[j]>k-pn[i])
   		{
   			j--;
   		}
   		books=max(books,i+j);
   }

   cout << books << endl;
   	

   return 0;
}




   


 

Measured memory_bytes: 9852
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const ll MX = 1e5, inf = 1e9 + 7;

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

	ll n;
	cin >> n;
	vi64 val(1, 0);
	ll i = 1;
	while (true) {
		val.pb(i * i * i * i * i);
		if (val[i] - val[i - 1] > n)break;
		i++;
	}
	for (int j = 0; j < i; j++) {
		for (int k = 0; k <= j; k++) {
			if (val[j] - val[k] == n) {
				cout << j << ' ' << k << endl; return 0;
			}
			else if (val[j] + val[k] == n) {
				cout << j << " -" << k << endl; return 0;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 3600
n,*a=gets(p).split.map(&:to_i)
q,r=a.inject(:+).divmod(n*(n+1)/2)
a<<a[0]
puts r==0&&a.each_cons(2).all?{|v,w|k=w-v-q;k<=0&&k%n==0} ? "YES" : "NO"

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

typedef pair<ll, ll> P;


void counting_sort(vector<ll> &a, vector<ll> &b, ll k, ll n) {
    vector<ll> c(k + 1, 0);
    rep(i, n) c[a[i]]++;
    for (int i = 1; i <= k; i++) c[i] = c[i] + c[i - 1];
    for (ll i = n - 1; i >= 0; i--) {
        ll ae = a[i];
        ll aec = c[ae];
        b[aec - 1] = ae;
        c[ae]--;
    }
}

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

    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i];
    ll k = *max_element(a.begin(), a.end());
    counting_sort(a, b, k, n);
    print_line(b);
}



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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main() 
{	
	fast;
	ll n,k; cin>>n>>k; ll arr[n]; for(ll i = 0; i < n; i++) cin>>arr[i];
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for(ll i = 2; i < n; i++)
	{
		dp[i] = abs(arr[i] - arr[i-1]) + dp[i-1];
		ll j = 2; ll tt = k-1;
		while(i >= j  && tt > 0)
		{
			dp[i] = min(dp[i] ,abs(arr[i] - arr[i-j]) + dp[i-j] );
			j++;
			tt--;
		}
	}
	cout << dp[n-1] << endl;
 	return 0;
}

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

int main(){
    int n;
    cin >> n;
    ll a[n];
    ll b[n];
    ll c[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
        c[i]=a[i];
    }
    ll ans1=0;
    ll ans2=abs(b[0]-1);
    ll ans3=abs(c[0]+1);
    b[0]=1;
    c[0]=-1;
    for(int i=1;i<n;i++){
        a[i]+=a[i-1];
        if(a[i]>=0&&a[i-1]>0){
            ans1+=abs(a[i]+1);
            a[i]=-1;
        }else if(a[i]<=0&&a[i-1]<0){
            ans1+=abs(a[i]-1);
            a[i]=1;
        }
    }
    for(int i=1;i<n;i++){
        b[i]+=b[i-1];
        if(b[i]>=0&&b[i-1]>0){
            ans2+=abs(b[i]+1);
            b[i]=-1;
        }else if(b[i]<=0&&b[i-1]<0){
            ans2+=abs(b[i]-1);
            b[i]=1;
        }
    }
    for(int i=1;i<n;i++){
        c[i]+=c[i-1];
        if(c[i]>=0&&c[i-1]>0){
            ans3+=abs(c[i]+1);
            c[i]=-1;
        }else if(c[i]<=0&&c[i-1]<0){
            ans3+=abs(c[i]-1);
            c[i]=1;
        }
    }
    if(a[0]==0){
        cout << min(ans2,ans3) << endl;
    }else{
        cout << min(ans1,min(ans2,ans3)) << endl;
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if (k - a <= 0) {
    cout << k << "\n";
    return 0;
  }
  
  if (k - a - b <= 0) {
    cout << a << "\n";
    return 0;
  }
  
  cout << a - (k - a - b) << "\n";  
  return 0;
}

Measured memory_bytes: 3624
package main
import "fmt"
func main() {
  const mod int64 = 1000000007
  var h,w int
  var s string
  fmt.Scan(&h,&w)
  var dp [][]int64 = make([][]int64,h+2)
  dp[0] = make([]int64,w+2)
  dp[h+1] = make([]int64,w+2)
  for j:=0;j<w+2;j++ { dp[0][j],dp[h+1][j] = -1,-1 }
  for i:=1;i<h+1;i++ {
    dp[i] = make([]int64,w+2)
    fmt.Scan(&s)
    dp[i][0],dp[i][w+1] = -1,-1
    for j:=1;j<w+1;j++ {
      if s[j-1:j] == "#" { dp[i][j] = -1 }
    }
  }
  dp[1][1] = 1
  for i:=1;i<h+1;i++ {
    for j:=1;j<w+1;j++ {
      if dp[i][j] < 0 { continue }
      if dp[i-1][j] >= 0 { dp[i][j] += dp[i-1][j] }
      if dp[i][j-1] >= 0 { dp[i][j] += dp[i][j-1] }
      dp[i][j] %= mod
    }
  }
  fmt.Println(dp[h][w])
}

Measured memory_bytes: 9216
#include<stdio.h>

int main(){
  int n,a,b,ans;
  scanf("%d%d%d",&n,&a,&b);
  if(a<=b)printf("%d ",a);
  else printf("%d ",b);
  if((ans=n-(a+b))<0) printf("%d\n",ans*(-1));
  else printf("0\n");
}


Measured memory_bytes: 128
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime

def main():
    q=int(input())
    is_prime = primes(10**5+1)
    a = [0 for i in range(10**5+1)]
    for i in range(3,10**5+1):
        if is_prime[i] and is_prime[(i+1)//2]:
            a[i]=a[i-1]+1
        else:
            a[i]=a[i-1]

    for i in range(q):
        l,r=map(int,input().split())
        print(a[r]-a[l-1])

main()

Measured memory_bytes: 5160
#include <iostream>
#define ll long long
using namespace std;

int main(){
  ll n; cin>>n;
  ll sum=0; ll q;
  
  for(int i=1;i<=n;i++){
    q=n/i;
    sum = sum + i*q*(q+1)/2;
  }
  
  cout<<sum;
  
  return 0;
}

Measured memory_bytes: 3624
import fractions
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//fractions.gcd(c,d)

count_c = b//c - (a-1)//c
count_d = b//d - (a-1)//d
count_cd = b//g -(a-1)//g
count_s = count_c+count_d-count_cd
print(b-a+1-count_s)

Measured memory_bytes: 5048
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

void chmin(int *a,int *b){
    if(*a>*b+1){
        *a = *b+1;
    }
}

int main(void){
    int H,W;cin>>H>>W;
    vector<vector<bool>> S(H,vector<bool>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char a;cin >> a;
            if(a=='#'){
                S[i][j] = 0;
            }else{
                S[i][j] = 1;
            }
        }
    }
    int max = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            while(1){
                if(S[i][j]==0)break;
                vector<vector<int>> dp(H,vector<int>(W,1000000));
                dp[i][j] = 0;
                int count = 0;
                while(count<H*W/2){
                    for(int m=0;m<H;m++){
                        for(int n=0;n<W;n++){
                            if(m-1>=0&&S[m-1][n]==1){
                                chmin(&dp[m-1][n],&dp[m][n]);
                            }
                            if(m+1<H&&S[m+1][n]==1){
                                chmin(&dp[m+1][n],&dp[m][n]);
                            }
                            if(n-1>=0&&S[m][n-1]==1){
                                chmin(&dp[m][n-1],&dp[m][n]);
                            }
                            if(n+1<W&&S[m][n+1]==1){
                                chmin(&dp[m][n+1],&dp[m][n]);
                            }
                        }
                    }
                    count++;
                }
                for(int k=0;k<H;k++){
                    for(int l=0;l<W;l++){
                        if(max<dp[k][l]&&dp[k][l]!=1000000){
                                max = dp[k][l];
                        }
                    }
                } 
                break;
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int n; cin >> n;
  ll ans = 0;
  vi in(n);
  rep(i,n) cin >> in[i];
  sort(ALL(in),greater<int>());
  rep(i,n){
    ans += (i%2?-in[i]:in[i]);
  }
  cout <<ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpl;

double EPS = 1e-9;
int INF = 1000000005;
ll INFF = 1000000000000000005LL;
#define mod 1000000007
#define PI 3.141592653589793238
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define PBO pop_back
#define dl "\n"

#define test  \
    ll t;     \
    cin >> t; \
    while (t--)

#define fast()                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))

#define fi(a, b, c) for (ll a = b; a < c; ++a)
#define fd(a, b, c) for (ll a = c - 1; a >= b; --a)
#define fei(a, b, c) for (ll a = b; a <= c; ++a)
#define fed(a, b, c) for (ll a = c; a >= b; --a)
#define fs(a, b) for (auto &a : b)

inline void OPEN()
{
    // #ifdef ONLINE_JUDGE
    //     freopen("input.in", "r", stdin);
    //     freopen("output.in", "w", stdout);
    // #endif
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    vll v(m);
    fi(i, 0, m)
    {
        cin >> v[i];
    }
    ll tot = accumulate(ALL(v), 0);
    (n - tot < 0) ? cout << "-1" << dl : cout << n - tot << dl;
}

int main()
{
    fast();
    // OPEN();
    solve();
    // test
    // {
    //     solve();
    // }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int e[128];
  int dp[2048][2048];
  int n,m,l;
  string s;
  while(1){
    cin >> m >> n;
    if(m==0) return 0;
    for(int i=0;i<n;i++){
      cin >> s;
      e[i]=0;
      l=s.length();
      for(int j=0;j<l;j++){
        if(s[l-j-1]=='1') e[i]+=(1<<j);
      }
    }
    for(int i=0;i<(1<<m);i++){
      for(int j=0;j<(1<<m);j++){
        dp[i][j]=0;
      }
    }
    for(int i=0;i<(1<<m);i++){
      map<int,int> mp;
      for(int j=0;j<n;j++){
        if(mp.find(i&e[j])==mp.end()) mp[i&e[j]]=1;
        else mp[i&e[j]]++;
      }
      for(auto it:mp){
        if(it.second>1){
          dp[i][it.first]=100;
        }
      }
    }
    for(int i=(1<<m)-1;i>=0;i--){
      for(int j=0;j<(1<<m);j++){
        if(i^(i|j)==0){
          // cout << i SP j << endl;
          if(dp[i][j]==0) continue;
          for(int k=0;k<m;k++){
            if(!(i&(1<<k))){
              dp[i][j]=min(dp[i][j],max(dp[i|(1<<k)][j],dp[i|(1<<k)][j|(1<<k)])+1);
            }
          }
        }
        // cout << dp[i][j] << " ";
      }
      // cout << endl;
    }
    cout << dp[0][0] << endl;
  }
  return 0;
}



Measured memory_bytes: 19548
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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




/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    string S,T;
    cin >> S >> T;
    int cnt =0;
    REP(i,3){
        if(S[i]==T[i]){
            ++cnt;
        }
    }
    cout << cnt << endl;
    return;
}



// ----------------------------------------------
int main(){

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>x[12000];int n,m,a,b,dist[12000],c[12000];
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){cin>>a>>b;x[a].push_back(b);c[b]++;}
	queue<int>Q;for(int i=0;i<n;i++){if(c[i]==0)Q.push(i);}
	while(!Q.empty()){
		int a1=Q.front();Q.pop();
		for(int i=0;i<x[a1].size();i++){
			if(dist[x[a1][i]]<dist[a1]+1){
				dist[x[a1][i]]=dist[a1]+1;Q.push(x[a1][i]);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){if(dist[j]==i)cout<<j<<endl;}
	}
	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

ll N, A, B, C, D;

map<ll, ll> mp;

ll dfs(ll now){
    if(mp.count(now)) return mp[now];
    ll a = now%2, b = now%3, c = now%5;
    ll m = INF;
    if(a <= 1) chmin(m, a*D+A+dfs(now/2));
    if(a >= 1) chmin(m, (2-a)*D+A+dfs(now/2+1));
    if(b <= 1) chmin(m, b*D+B+dfs(now/3));
    if(b >= 2) chmin(m, (3-b)*D+B+dfs(now/3+1));
    if(c <= 2) chmin(m, c*D+C+dfs(now/5));
    if(c >= 3) chmin(m, (5-c)*D+C+dfs(now/5+1));
    ll ret;
    if(m/D > now) ret = D*now;
    else ret = m;
    mp[now] = ret;
    return ret;
}

int main(){
    int T;
    cin >> T;
    rep(t, T){
        cin >> N >> A >> B >> C >> D;
      	mp[0] = 0, mp[1] = D;
        cout << dfs(N) << endl;
        mp.clear();
    }
}

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

int main() 
{
	int n;
	scanf("%d", &n);
	long long res = 1, v;
	bool f = true;
	while (n--) {
		scanf("%lld", &v);
		if (!v) {
			f = true;
			res = 0;
		}
		else if (res >= ((long long)1e18) / v + 1) f = false;
		res *= v;
	}
	if (f) printf("%lld\n", res);
	else printf("-1\n");
	return 0;
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int bit[30][N], a[N], b[N], dx[N];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (int k = 0; k < 28; k++)
		for (int i = 1; i <= n; i++)
			bit[k][i] = b[i] & ((1 << (k + 1)) - 1);
	for (int i = 0; i < 28; i++)
		sort(bit[i] + 1, bit[i] + n + 1);
	int ans = 0;
	for (int k = 1; k <= 28; k++)
		for (int i = 1; i <= n; i++) {
			dx[i] ^= (1 << (k - 1)) & a[i];
			int x = lower_bound(bit[k - 1] + 1, bit[k - 1] + n + 1, (1 << k) - dx[i]) - bit[k - 1];
			ans ^= ((n - x + 1) % 2) << k;
		}
	int a0, a1, b1, b0;
	for (int k = 0; k <= 28; k++) {
		a0 = a1 = b0 = b1 = 0;
		for (int i = 1; i <= n; i++)
			if ((1 << k) & a[i])
				a1++; 
			else 
				a0++;
		for (int i = 1; i <= n; i++)
			if ((1 << k) & b[i])
				b1++;
			else
				b0++;
		ans ^= (((1ll * a1 * b0 % 2 + 1ll * a0 * b1 % 2) % 2) << k);
	}
	printf("%d", ans);
}

Measured memory_bytes: 24832