akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pb push_back
#define x first
#define y second
 
int main()
{
	ll n,k,i,j;
	cin>>n>>k;
	ll h[n+1],c[n+1];
	for(i=1;i<=n;i++)
	{
		cin>>h[i];
		c[i]=1000000000;
	}
	c[1]=0;
	for(i=2;i<=k && i<=n;i++)
		c[i]=abs(h[i]-h[1]);
	for(i=k+1;i<=n;i++)
	{
		for(j=i-1;j>=i-k;j--)
		{
			c[i]=min(c[i],c[j]+abs(h[j]-h[i]));
		}
	}
	cout<<c[n];
}

Measured memory_bytes: 1792
<?php

// define('DEBUG', true);
define('DEBUG', false);

// define('MOD', 1000000007);

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));

for ($i = 0; $i < $N; $i++) {
    $arr[$a[$i]]++;
}

foreach ($arr as $key => $val) {
    $x = $arr[$key] + $arr[$key+1] + $arr[$key+2];
    $ans = max($ans, $x);
}

echo $ans . PHP_EOL;


Measured memory_bytes: 16884
#include<iostream>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  rep(i,A,B) {
    if (i - A < K) cout << i << endl;
    else if (B - i < K) cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	k := sc.ReadInt()

	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = sc.ReadInt()
	}

	sort.Ints(p)

	ans := 0
	for i := 0; i < k; i++ {
		ans += p[i]
	}

	fmt.Println(ans)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1776
A,B,C,X,Y = map(int,input().split())

if C > (A+B)/2:
    print(A*X+B*Y)
elif X > Y and C > A/2:
    print(C*Y*2+A*(X-Y))
elif X > Y:
    print(C*X*2)
elif C > B/2:
    print(C*X*2+B*(Y-X))
else:
    print(C*Y*2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,m,K;
void solve(){
	scanf("%d",&n);
	int ans=0;
	for(int i=1;i<=n;i++){
		int x=i;
		int cnt=0;
		while(x){
			cnt^=1;
			x/=10;
		}
		if(cnt)ans++;
	}
	printf("%d\n",ans);
}
int main() {
	solve();
	return 0;
}

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

#define INF INT_MAX

using namespace std;

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

int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	int R,G,B,N;
	cin >> R >> G >> B >> N;
	int ans = 0;
	for(int i = 0;i <= N;i+=R){
		for(int j = 0;j+i <= N;j+=B){
			if((N-(i+j)) % G == 0 ){
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 1; i <= n; i++)

template <typename T>
T _gcd(T a, T b) {
    return b ? _gcd(b, a%b) : a;
}

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

    long long n;
    cin >> n;

    long long ans = 0;

    rep(i, n){
        rep(j ,n){
            rep(k, n){
                ans += _gcd(_gcd(i, j), k);
            }
        }
    }

    cout << ans << endl;
}

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

int main()
{
    std::string t,k,s = "~";
    std::cin >> t >> k;
    int n = t.size();

    for(int i = 0; i < n - (int)k.size() + 1; i++){
        std::string tmp = t;
        bool res = true;
        for(int j = i; j <  i + (int)k.size(); j++){
            if(tmp[j] != '?' && tmp[j] != k[j - i])res = false;
            /*
            std::cout << tmp[j];
            std::cout << k[j - i];
            std::cout << std::endl;
            */
        }
        if(res == true){
            for(int j = i; j < i + (int)k.size(); j++){
            tmp[j] = k[j - i];
            }
            for(int j = 0; j < n; j++){
                if(tmp[j] == '?')tmp[j] = 'a';
            }
            s = std::min(tmp,s);
        }        
    }
    if(s == "~"){
        std::cout << "UNRESTORABLE" << std::endl;
    }else{
        std::cout << s << std::endl;
    }
}

Measured memory_bytes: 256
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


a,b,c=input_list()
before=c
for _ in range(10):
    now=before*a-b
    print(now)
    before=now

Measured memory_bytes: 3316
from collections import Counter
import copy
from itertools import combinations
import math


def A(s):
  if s == 'RRR':
    return 3
  elif s == 'RRS':
    return 2
  elif s == 'RSR':
    return 1
  elif s == 'SRR':
    return 2
  elif s == 'RSS':
    return 1
  elif s == 'SRS':
    return 1
  elif s == 'SSR':
    return 1
  elif s == 'SSS':
    return 0
  l = 0
  max_l = 0
  for i in range(len(s)):
    if i == 0 and s[i] == 'R':
      l += 1
    elif s[i - 1] == s[i] and s[i] == 'R':
      l += 1
    else:
      l = 0
    if l > max_l:
      max_l = l
  return max_l


def B(N, Ls):

  def _can_tri(a, b, c):
    if a == b or a == c or b == c:
      return False
    tmp_a, tmp_b, tmp_c = sorted([a, b, c])
    if tmp_a + tmp_b > tmp_c:
      return True
    return False

  ans = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        if _can_tri(Ls[i], Ls[j], Ls[k]):
          # print(i + 1, j + 1, k + 1)
          ans += 1
  return ans


def C(X, K, D):
  abs_x = int(abs(X))
  if K * D <= abs_x:
    return abs_x - K * D
  else:
    a = K - math.floor(abs_x / D)
    # print(a, abs_x, D, math.floor(abs_x / D))
    if a % 2 == 0:
      return abs_x % D
    else:
      return D - abs_x % D


def main():
  # s = input()
  # print(A(s))
  # N = int(input())
  # Ls = [int(x) for x in input().split(' ')]
  # print(B(N, Ls))
  X, K, D = [int(x) for x in input().split(' ')]
  print(C(X, K, D))


if __name__ == '__main__':
  main()


Measured memory_bytes: 9648
#include<iostream>

using namespace std;

int sum = 0;
void check(int i,int a, int b)
{
	int j = i;
	int tmp = 0;
	while(i > 0){
		tmp += i % 10;
		i /= 10;
	}
	if(tmp >= a && tmp <= b)
		sum += j;

}
int main()
{
	int n,a,b;
	cin >> n >> a >> b;
	for(int i=1; i<=n; i++){
		check(i,a,b);
	}
	cout << sum << 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[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		long a[] = new long[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		Arrays.sort(a);

		long ai = a[n - 1];
		long aj = a[0];
		for (int i = 0; i < n; i++) {
			if (a[i] == ai)
				continue;
			if (Math.abs(a[i] - ai / 2) <= Math.abs(aj - ai / 2)) {
				aj = a[i];
			}
		}
		System.out.println(ai + " " + aj);
	}
}


Measured memory_bytes: 51588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int n; cin>>n;
  vector<int> f(n+1);
  for(int i=1; i<=100; i++){
    for(int j=1; j<=100; j++){
      for(int k=1; k<=100; k++){
        int a = i*i+j*j+k*k+i*j+j*k+k*i;
        if(a<=n) f.at(a)++;
      }
    }
  }
  for(int i=0; i<n; i++){
    cout<<f.at(i+1)<<endl;
  }
  
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  if((b-a+1)<=2*k){
    int sum=a;
    rep(i,b-a+1){
  cout <<sum<<endl;
    sum++;}
  }
  
  else{
    for(int tmp=0;tmp<k;tmp++)
      cout<<a+tmp<<endl;
     for(int tmp=b-k+1;tmp<b+1;tmp++)
      cout<<tmp<<endl;
}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cmath>
const int MaxN = 1e6;
using namespace std;
int pre[2 * MaxN + 5] , last[MaxN + 5] , other[MaxN + 5];
int all , n , res[MaxN + 5];
void Build(int u , int v){
	pre[++all] = last[u];
	last[u] = all;
	other[all] = v;
}
void dfs(int x , int fa){
	int ed = last[x];
	while(ed != -1){
		int dr = other[ed];
		if(dr != fa){
			dfs(dr , x);
			res[x] ^= res[dr] + 1;
		}
		ed = pre[ed];
	}
}
int main()
{
	while(~scanf("%d" , &n)){
		all = -1;
		memset(last , -1 , sizeof(last));
		memset(res , 0 , sizeof(res));
		for(int i = 1;i <= n - 1;i++){
			int u , v;
			scanf("%d%d" , &u , &v);
			Build(u , v); Build(v , u);
		}
		dfs(1 , 0);
		if(res[1]) printf("Alice\n");
		else printf("Bob\n");
	}
}

Measured memory_bytes: 19200
#include <iostream>

using namespace std;

int main()
{
int A,B,C,D;
cin >> A >> B >> C >> D;

int L = A+B;
int R = C+D;

if (L<R)
{
cout << "Right" << "\n";
}

else if (L>R)
{
cout << "Left" << "\n";
}
else
cout << "Balanced" << "\n";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;



int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll n=s.size();
    vector<ll> count(n);
    for(ll i=0;i<n;i++){
        if(s[i]=='a'){
            count[i]=0;
            continue;
        }
        count[i]=26-(s[i]-'a');
    }
    for(ll i=0;i<n-1;i++){
        if(count[i]<=k){
            s[i]='a';
            k-=count[i];
        }
    }
    k%=26;
    if(k>=count[n-1]) s[n-1]='a'+(k-count[n-1]);
    else s[n-1]=s[n-1]+k;
    cout << s << endl;
    return 0;
}  


Measured memory_bytes: 4300
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    ll X, N;
    cin >> X >> N;

    set<ll> P;
    for (ll i = 0; i < N; i++)
    {
        ll pi;
        cin >> pi;
        P.insert(pi);
    }

    ll ans = 0;
    for (ll i = 0; i <= 101; i++)
    {
        if (abs(i - X) < abs(ans - X))
        {
            if (P.count(i) == 0)
            {
                ans = i;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<string> W(110);
	int i, j;
	bool flag=true;
	string str;
	for(i=0; i<N; ++i) cin >> W[i];
	for(i=1; i<N; ++i){
	    for(j=0; j<i; ++j) if(W[j]==W[i]) flag=false;
	    str=W[j-1];
	    if(str[str.size()-1]!=W[i][0]) flag=false;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  
  //cout<<a<<" "<<b<<endl;
  
  int x[2000001];
  for(int i=0; i<=200000; i++ ){
    x[i]=i-100000;
  }
  
  for(int i=b-a+1+100000; i<=a+b-1+100000; i++){
    cout<<x[i]<<" "; 
  
  }
  
}

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

#define ios ios_base::sync_with_stdio(0); cout.tie(0);cin.tie(0);
#define endl "\n"
#define f first
#define s second

using namespace std;

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

const int N = (int)(6e5), A = (int)(1e7 + 2);

void solve() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    ll sum = 0;
    ll dp[n], ans = 0;
    for (int i = 0; i < n; ++ i) {
        if (i % 2 == 1) {
            sum -= a[i];
        }
        else {
            sum += a[i];
            ans += a[i];
        }
        dp[i] = sum;
    }
    multiset <ll> odd, even;
    //even.insert(0);
    odd.insert(0);
    even.insert(dp[0]);
    ll copans = ans;
    for (int i = 0; i < n; ++ i) {
        if (i % 2 == 0) {
            ll l = *(even.rbegin());
            ans = max(ans, copans - (dp[i] - l));
            even.insert(dp[i]);
        }
        else {
            ll l = *(odd.rbegin());
            ans = max(ans, copans - (dp[i] - l));
            odd.insert(dp[i]);
        }
    }
    cout << ans;
}

int main() {
    ios
    int a;
    cin >> a;
    cout << a + a * a + a * a * a;
    return 0;
}


Measured memory_bytes: 3608
# include<bits/stdc++.h>
using namespace std;
const int maxn=50005;

int n,a,b,c;

int main ()
{
    while(~scanf("%d%d%d", &a, &b, &c)){
        if(b==c)cout<<a<<endl;
        else if(a==c)cout<<b<<endl;
        else if(a==b)cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n;
bool ok(int a,int b,vector<string>&s){
    char t[305][305];
    rep(i,n){
        rep(j,n){
            t[i][j] = s[(i-a+n)%n][(j-b+n)%n];
        }
    }
    rep(i,n){
        rep(j,n){
            if(t[i][j] != t[j][i]){
                return false;
            }
        }
    }
    return true;
}
int main(){
    cin >> n;
    vector<string>s(n);
    rep(i,n){
        cin >> s[i];
    }
    int ans = 0;
    rep(i,n){
        if(ok(0,i,s)){
            ans += n;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
#define MOD = 1e9+7
#define rep(i,n) for(int i=0;i<(n);++i)
const double PI=3.14159265358979323846; 
const int INF = 1001001001;
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  ll ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i] != t[i]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3916
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

struct UnionFind {
    int n, cc, *u;
    UnionFind() : n(0), cc(0), u(NULL) {}
    UnionFind(int n_) : n(n_), cc(n_) {
	u = new int[n_];
	memset(u, -1, sizeof (int) * n);
    }
    UnionFind(const UnionFind &y) : n(y.n), cc(y.cc) {
	u = new int[y.n];
	memcpy(u, y.u, sizeof (int) * n);
    }
    ~UnionFind() {
	delete[] u; u = NULL;
	n = cc = 0;
    }
    friend void swap(UnionFind &x, UnionFind &y) {
	swap(x.n, y.n); swap(x.cc, y.cc); swap(x.u, y.u);
    }
    UnionFind& operator=(UnionFind y) { 
	swap(*this, y);
	return *this;
    }
    int root(int x) {
	int y = x, t;
	while (u[y] >= 0) y = u[y];
	while (x != y) { t = u[x]; u[x] = y; x = t; }
	return y;
    }
    bool link(int x, int y) {
	x = root(x); y = root(y);
	if (x == y) return false;
	if (u[y] < u[x]) swap(x, y);
	u[x] += u[y]; u[y] = x; cc--;
	return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -u[root(x)]; }
    int count() { return cc; }
};

const int SIZE = 100011;
int N;
int X[100011], Y[100011];
VI vx[100011], vy[100011];
int xc[SIZE*2], yc[SIZE*2];
int cnt[SIZE*2];

void MAIN() {
    UnionFind U(2 * SIZE);
    scanf("%d", &N);
    REP (i, N) {
	scanf("%d%d", X+i, Y+i);
	vx[X[i]].push_back(i);
	vy[Y[i]].push_back(i);

	U.link(X[i], SIZE + Y[i]);
    }

    REP (i, SIZE) {
	EACH (e, vx[i]) U.link(SIZE+Y[vx[i][0]], SIZE+Y[*e]);
	EACH (e, vy[i]) U.link(X[vy[i][0]], X[*e]);
    }

    REP (i, N) {
	cnt[U.root(X[i])]++;
    }
    REP (i, SIZE) {
	if (vx[i].size()) xc[U.root(X[vx[i][0]])]++;
	if (vy[i].size()) yc[U.root(X[vy[i][0]])]++;
    }

    LL ans = 0;
    REP (i, SIZE*2) if (U.root(i) == i && xc[i] >= 2 && yc[i] >= 2) {
	ans += (LL) xc[i] * yc[i] - cnt[i];
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 10368
D, G = map(int, input().split())
PC = [list(map(int, input().split())) for _ in range(D)]

# remainは、まだ解いていない問題
def dfs(i, sum, count, remain):
    global answer
    #iがD-1まででどの問題を全部解くかどうかが決定されている
    if i == D:
        # sumがGに達していない場合、remainの中で最大のものを使う　
        if sum < G:
            use = max(remain)
            n = min(PC[use-1][0], -(-(G-sum)//(use*100)))
            count += n
            sum += 100*use*n
        if sum >= G:
            answer = min(answer, count)
    # この問題を解くかどうか２つの場合で、次の問題に渡して再帰関数を使う
    else:
        dfs(i+1, sum, count, remain)
        dfs(i+1, sum + 100*(i+1)*PC[i][0] + PC[i][1], count + PC[i][0], remain-{i+1})
        
answer = float('inf')
dfs(0, 0, 0, set(range(1, D+1)))
print(answer)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <assert.h>
#include <string>
#define int long long
using namespace std;
int m=1000000007;
bool visited[100005];
int ans = 0;
std::vector<int> g[100005];
void dfs(int s){
  visited[s] = true;
  ans++;
  for(int i = 0; i < g[s].size(); i++){
    if(visited[g[s][i]] == false){
      dfs(g[s][i]);
    }
  }
}
int32_t main(){
	int N;
	cin >> N;
	int a[N+1],b[N+1],c[N+1];
	for(int i = 1; i <= N; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i = N; i > 1; i--){
		a[i-1] += max(b[i],c[i]);
		b[i-1] += max(a[i],c[i]);
		c[i-1] += max(a[i],b[i]);
	}
	int max1 = max(a[1],b[1]);
	max1 = max(max1,c[1]);
	cout << max1 << endl;
}


Measured memory_bytes: 4992
n,m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
sumx = 0
sumy = 0
for i in 1..n
  sumx += (i-1)*x[i-1]-(n-i)*x[i-1]
end

for i in 1..m
  sumy += (i-1)*y[i-1]-(m-i)*y[i-1]
end
sum = sumx*sumy
puts sum%(10**9+7)


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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
    int neko =0;
    int inu = 0;
  for(int i=0;i<N;i=i+2){
    neko += vec.at(i);
  }
  for(int i=1;i<N;i=i+2){
    inu += vec.at(i);
  }
  cout<<neko-inu<<endl;
}


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

int digit(ll a){
    int count = 0;
    while(a!=0){
        a /= 10;
        count += 1;
    }
    return count;
}
int main() {
    int a,b; cin >> a >> b;
    string s; cin >> s;
    int ans = 0;
    rep(i,a+b+1){
        if(i!=a){
            if(s[i]=='-'){
                cout << "No" << endl;
                ans += 1;
                break;
            }
        }else{
            if(s[i]!='-'){
                cout << "No" << endl;
                ans += 1;
                break;
            }
        }
    }
    if(ans==0){
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

bool prm[1010];

int main(){
    int n; cin>>n;
    vector<int> cnt;
    for(int i=2;i<=n;i++)prm[i]=true;
    for(int i=2;i<=n;i++){
        if(!prm[i])continue;
        int tmp=0;
        for(int p=i;p<=n;p*=i){
            tmp+=n/p;
        }
        cnt.push_back(tmp);
        for(int p=i+i;p<=n;p+=i){
            prm[p]=false;
        }
    }
    ll ans=1;
    for(int i:cnt){
        (ans*=(i+1))%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

var (
	BufferSize = 100
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	b := scanInt(sc)

	ans := a * b
	if a > 9 || b > 9 {
		ans = -1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
//typedef long long int LL;
//typedef __int64 LL;

int H, W;
char board[305][305];
int cost[305][305];
int dp[305][305];

int DP(int r1, int r2, const int& c1, const int&c2) {
	if (r1 == -1) return 0;
	if (r2 == -1) return 0;

	int &ret = dp[r1][r2];
	if (ret != -1) return ret;
	int now = DP(r1 - 1, r2, c1, c2);
	ret = cost[r1][r2] + now;
	now = DP(r1, r2 - 1, c1, c2);
	ret = MIN(ret, cost[r1][r2] + now);
	return ret;
}

int COST_DP(int r1, int r2, const int& c1, const int& c2) {
	if (r1 == -1) return 0;
	if (r2 == -1) return 0;
	int &ret = cost[r1][r2];
	if (ret != -1) return ret;
	ret = 0;
	ret = board[r1][c1] == board[r2][c2];
	ret += COST_DP(r1 - 1, r2 - 1, c1, c2);
	return ret;
}

int calc(int c1) {
	int c2 = c1 + 1;
	int offset = 300;
	MEM(cost, -1);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < H; j++) {
			cost[i][j] = COST_DP(i, j, c1, c2);
		}
	}

	MEM(dp, -1);
	return DP(H - 1, H - 1, c1, c2);
}
int main()
{
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", board[i]);
	}

	int ans = 0;
	for (int i = 0; i < W - 1; i++) {
		ans += calc(i);
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int m, d, res, i, j;

int main() {
scanf("%d %d", &m, &d);
res = 0;
for (i=1;i<=m;i++) for (j=22;j<=d;j++) if (j % 10 >= 2 && (j % 10) * (j / 10) == i) res++;
printf("%d\n", res); 
return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

al = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
ans = str()

for i in s:
    for j in range(len(al)):
        if i == al[j] and j + n < len(al):
            ans += al[j+n]
        elif i == al[j] and j + n > len(al)-1:
            ans += al[abs(len(al)-j-n)]

print(ans)


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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(15)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)

double x = 6.28318530717958623200;

int32_t main() { fastio;
	int n; cin >> n;
	pout << n * x << endl;
	return 0;
}


Measured memory_bytes: 3804
s = int(input())
if 1 <= s // 100 <= 12:
    if 1 <= s % 100 <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= s % 100 <= 12:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=0;
		int i=1;
		while(true) {
			a=sc.nextInt();
			if(a!=0) {
				System.out.println("Case "+i+": "+a);
				i++;
			}else {
				break;
			}
		}
	}

}



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

int main() {
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  vector <long long> z(4);
  z.at(0) = a * c;
  z.at(1) = a * d;
  z.at(2) = b * c;
  z.at(3) = b * d;
  sort(z.begin(),z.end());
  cout << z.at(3);
  
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    string S; cin>>S;
    string out =  S.substr(0,3);
    cout<<out<<endl;

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    map<string,ll> mp;
    ll N;
    cin >> N;
    ll cnt = 0;
    for (ll i = 0;i<N;i++) {
        string s;
        cin >> s;
        if (mp[s] == 0) {
            mp[s]++;
            cnt++;
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 19228
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    vector<int> a(3,0);
    vector<int> b(3,0);

    vector<vector<int>> c(3,vector<int>(3));
    REP(i,3) {
        REP(j,3) {
            cin >> c[i][j];
        }
    }

    // a_1 = 0からb_1,b_2,b_3を出す。
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    // a_2,a_3を出す
    a[1] = c[1][0]-b[0];
    a[2] = c[2][0]-b[0];

    REP(i,3) {
        REP(j,3) {
            if (c[i][j] != (a[i]+b[j])) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A=0,B=0,M=0,amin=200000,bmin=200000,tmin=200000;
  scanf("%d%d%d",&A,&B,&M);
  int a[A],b[B],x[M],y[M],c[M],i,total[M+1];
  for(i=1;i<=A;i++){
    scanf("%d",&a[i]);
    if(a[i]<amin){
      amin=a[i];
    }
  }for(i=1;i<=B;i++){
    scanf("%d",&b[i]);
    if(b[i]<bmin){
      bmin=b[i];
    }
  }for(i=1;i<=M;i++){
    scanf("%d%d%d",&x[i],&y[i],&c[i]);
    total[i]=a[x[i]]+b[y[i]]-c[i];
  }
  total[0]=amin+bmin;
  for(i=0;i<=M;i++){
    if(total[i]<=tmin){
      tmin=total[i];
    }
  }
  cout<<tmin<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long 
const int MODN=998244353;
const int MAXN=3010;
using namespace std;

int dp[MAXN][MAXN];
int32_t main(){
    dp[0][0]=1;
    int n,k;cin>>n>>k;
    vector<int> arrmv(n+1);
    for(int i=0;i<n;i++)cin>>arrmv[i+1];
    vector<int> a=arrmv;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(k-a[i]>=0){
            if(k-a[i]>0)ans+=dp[i-1][k-a[i]]*(n-i+1);
            else ans+=i*(n-i+1);
                ans%=MODN;
        }
        for(int j=k;j>=0;j--){
            dp[i][j]+=dp[i-1][j];
            if(j-a[i]>0)dp[i][j]+=dp[i-1][j-a[i]];
            else if(j==a[i])dp[i][j]+=i;
            dp[i][j]%=MODN;
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	vector<ll> a,b,c;
	ll bc[100010];
	cin >> n;
	ll x;
	FOR(i,n){
		cin >> x;
		a.push_back(x);
	}
	FOR(i,n){
		cin >> x;
		b.push_back(x);
	}
	FOR(i,n){
		cin >> x;
		c.push_back(x);
	}
	sort(all(a));
	sort(all(b));
	sort(all(c));
	bc[n]=0;
	for(int i=n-1;i>=0;i--){
		
		bc[i]=n-(upper_bound(all(c),b[i])-c.begin());
		bc[i]+=bc[i+1];

	}
	ll ans=0;

	FOR(i,n){
		int y=upper_bound(all(b),a[i])-b.begin();
		ans+=bc[y];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
    long long n,lim,i,dig=20;
    scanf("%lld",&n);
    lim=sqrt(n);
    for(i=1;i<=lim;i++){
        if(n%i==0){
            if(log10(n/i)<dig){
                dig=log10(n/i);
            }
        }
    }
    printf("%lld",dig+1);
    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m;
    cin >> n >> m;

    vi p(m), y(m);
    map<int, vector<int>> mp;
    REP(i, m) {
        cin >> p[i] >> y[i];

        mp[p[i]].push_back(y[i]);
    }

    for (auto& p: mp) sort(all(p.second));
    REP(i, m) {
        int d = lower_bound(all(mp[p[i]]), y[i]) - mp[p[i]].begin() + 1;
        printf("%06d%06d\n", p[i], d);
    }
    
    return 0;
}


Measured memory_bytes: 13312
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

n = int(input()) - 1
ar = [int(i) for i in input().split()]
sm = ar[0]
for i in range(1, n):
    sm += min(ar[i], ar[i - 1])
sm += ar[n - 1]
print(str(sm))

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

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  if (N == 1) {
    if (a.at(0)%4 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    int x = 0, y = 0;
    for (int i = 0; i < N; i++) {
      if (a.at(i)%4 == 0) x++;
      else if (a.at(i)%2 == 1) y++;
    }
    if (N%2 == 0) {
      if (x >= y) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
    else {
      if (x >= y-1) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;

Vi yaku(ll nu){
    Vi vv;
    rep(i,(ll)sqrt(nu) + 1){
        if(i==0)continue;
        if(nu%i == 0){
            if(i!=1)vv.pb(i);
            if(i!=nu)vv.pb(nu/i);
        }
    }
    return vv;
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    Vi v = yaku(n);
    Vi vv = yaku(n-1);
    set<ll> s;
    ll n2;
    rep(i,v.size()){
        n2 = n;
        while(n2%v[i]==0){
            if(n2%v[i]==0){
                n2 /= v[i];
            }
        }
        if(n2 % v[i] == 1){
            s.insert(v[i]);
        }
    }
    rep(i,vv.size()){
        s.insert(vv[i]);
    }
    print(s.size());
    return 0;
}

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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	vector<int>Set;
	for (int i = 0; i < K; ++i) {
		if (A + i <= B) {
			Set.push_back(A + i);
		}
	}
	for (int i = 0; i < K; ++i) {
		if (A <= B - i) {
			Set.push_back(B - i);
		}
	}
	sort(Set.begin(), Set.end());
	Set.erase(std::unique(Set.begin(), Set.end()), Set.end());
	for (int i = 0; i < Set.size(); ++i) {
		cout << Set[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>

#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

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

constexpr int inf = (int)1e9;
constexpr double INF = 1e12, EPS = 1e-9;
constexpr int MX = 2010;
constexpr int mod = inf + 7;

int n, m, q, a[MX];
int L[MX][MX], R[MX][MX];
int memo[MX][MX];

int main() {
  int N;
  cin >> N;
  rep(i,N) {
    cin >> a[i];
  }

  int diff{0};
  bool aturn{true};

  sort(a, a + N, greater<int>());

  rep(i,N) {
    if (aturn) {
      diff += a[i];
    } else {
      diff -= a[i];
    }

    aturn = !aturn;
  }

  cout << diff << endl;
}

Measured memory_bytes: 888
/* nuttela - Soham Chakrabarti */

#include <bits/stdc++.h>
 
using namespace std;
 
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define ins insert
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define per(i,j,k) for(ll i=j;i>=k;--i)
#define scan(a,n) rep(i,0,n)cin>>a[i]
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define error freopen("error.txt","w",stderr)
#define ff first
#define ss second
 
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int N = 1e6+1;
const int MAX = 1e6+1; 
const int inf = INT_MAX;
const int mod = 1e9+7;

ll powm(ll a,ll b) {ll res=1LL;while(b) {if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll modmult(ll a,ll b) {ll r=0;a%=mod;while(b){if(b&1)r=(r+a)%mod;a=(a<<1)%mod;b>>=1;}return r;}
ll modexpo(ll a,ll b) {ll r=1;a%=mod;while(b){if(b&1)r=(r*a)%mod;a=(a*a)%mod;b>>=1;}return r;}

ll a[N],b[N];

int32_t main() {
    io;
    ld n,d;
    cin>>n>>d;
    ll cnt=0;
    rep(i,0,n) {
        ld x,y;
        cin>>x>>y;
        ld a=sqrt(x*x+y*y);
        // cout<<a<<endl;
        if(a<=d) {
            // cout<<x<<' '<<y<<endl;
            ++cnt;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3804
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
void fo (){fflush(stdout);}
using namespace std;
int main ()
{
  int n ;
  cin >> n ;
  map <int ,int > mp;
  for (int i =0 ; i < n ;i++)
  {
    char x;
    cin >> x;
    mp[x]++;
  }
  if (SZ(mp) == 3)
  {
    cout <<"Three\n";
  }else
  cout <<"Four\n";
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  bool res=false;
  for(int i=0;i<=x;i++){
    int b=x-i;
    if((2*b+4*i)==y)
      res=true;
  }
  if(res)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3616
from heapq import heappush, heappop

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

day = [[] for _ in range(10 ** 5)]
for a, b in ab:
    day[a - 1].append(b)

work, ans = [], 0
for i in range(m):
    for j in day[i]:
        heappush(work, -j)
    if len(work) > 0:
        ans -= heappop(work)
print(ans)


Measured memory_bytes: 101760
from bisect import bisect_left
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

s.sort()
t.sort()

for k in range(Q):
    x = int(input())
    ans = []
    ms = bisect_left(s, x)
    for i in [-1, 0]:
        if 0 <= ms + i <= A - 1:
            mt = bisect_left(t, s[ms + i])
            for j in [-1, 0]:
                if 0 <= mt + j <= B - 1:
                    ans.append(abs(s[ms + i] - x) + abs(t[mt + j] - s[ms + i]))
    mt = bisect_left(t, x)
    for i in [-1, 0]:
        if 0 <= mt + i <= B - 1:
            ms = bisect_left(s, t[mt + i])
            for j in [-1, 0]:
                if 0 <= ms + j <= A - 1:
                    ans.append(abs(t[mt + i] - x) + abs(s[ms + j] - t[mt + i]))
    print(min(ans))


Measured memory_bytes: 17008
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	vector<int> v;
	cin >> n;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	sort(v.begin(), v.end());
	long long sum = 0, ans = -1;
	for (int i = 0; i < n - 1; i++) {
		sum += v[i];
		if (sum * 2 < v[i + 1])ans = i;
	}
	cout << (ans == -1 ? n : n - ans - 1) << endl;
}

Measured memory_bytes: 892
n = int(input())
count = 0
for i in range(1, n + 1):
    if i % 2 == 0:
        continue
    c = 0
    for j in range(1, i + 1):

        if i % j == 0:
            c += 1
    if c == 8:
        count += 1
print(count)

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

int main() {
    string N;
    cin >> N;
    int ct = 0;;
    for (int i = 0; i < 3; ++i)
    {
        if (N[i] == N[i+1]) ct++;
        else ct = max(ct-1, 0);
        if (ct >= 2)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] inputvalue = Console.ReadLine().Split(' ');
        int val1 = int.Parse(inputvalue[0]);
        int val2 = int.Parse(inputvalue[1]);
        
        if((val1+val2)%2 == 0)
        {
            Console.WriteLine((val1 + val2) / 2);
        }
        else
        {
            Console.WriteLine("IMPOSSIBLE");
        }
    }
}



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, k, a[55];
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	vector<int> v;
	v.push_back(INF);
	i64 A = 0;
	i64 ans = 0;
	for(int i = 0; i <= n; i++){
		if(i != 0){
			v.push_back(a[i-1]);
			A += a[i-1];
		}
		sort(v.begin(),v.end());
		vector<int> vv;
		vv.push_back(INF);
		i64 B = 0;
		for(int j = 0; i+j <= n; j++){
			if(j != 0){
				vv.push_back(a[n-j]);
				B += a[n-j];
			}
			sort(vv.begin(),vv.end());
			if(i+j > k) break;
			chmax(ans, A+B);
			int l = 0, r = 0;
			i64 C = 0;
			for(int ii = 0; ii+i+j < k; ii++){
				if(v[l] == INF && vv[r] == INF) break;
				if(v[l] < vv[r]){
					C += v[l];
					l++;
				}
				else{
					C += vv[r];
					r++;
				}
				chmax(ans, A+B-C);
			}
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[51][2501][51];

int go(int ith , int sum , int count, int n, vi &a , int k){
    if(ith == n){
        if(count != 0){
            if(sum % count == 0 && sum / count == k){
                return 1;
            }
        }return 0;
    }
    if(dp[ith][sum][count] !=-1){
        return dp[ith][sum][count];
    }
    int total = 0;
    // if not selected
    total += go(ith + 1 , sum , count , n , a , k);
    // if selected
    total += go(ith + 1, sum + a[ith] , count + 1 , n , a , k);

    return dp[ith][sum][count] = total;
}

void solve() {
    int n , k;
    cin>>n>>k;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    memset(dp , -1 , sizeof(dp));
    cout<<go(0 , 0 ,0,  n , a , k);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 51072
#include <stdio.h>

long long int x,y;

int main(){
	scanf("%lld %lld",&x,&y);
	if(x>=0 && y>x){
		printf("%lld\n",y-x);
	}
	if(x>0 && y<=0 && y>=-x){
		printf("%lld\n",x+y+1);
	}
	if(x>0 && y<x && y>0){
		printf("%lld\n",x-y+2);
	}
	if(x>=0 && y<-x){
		printf("%lld\n",1-x-y);
	}
	if(x<0 && y<=0 && y>x){
		printf("%lld\n",y-x);
	}
	if(x<0 && y<-x && y>0){
		printf("%lld\n",1-x-y);
	}
	if(x<0 && y>=-x){
		printf("%lld\n",x+y+1);
	}
	if(x<0 && y<x){
		printf("%lld\n",x-y+2);
	}
}

Measured memory_bytes: 128
S = input()
ans = []
c = 0
if len(S)%2 == 0:
    t = len(S)//2
    for i in range(t - 1,-1,-1):
        ans.append(S[i])
    for i in range(t):
        if S[i+t] != ans[i]:
            c += 1
    print(c)

if len(S)%2 == 1:
    t = len(S)//2
    for i in range(t,-1,-1):
        ans.append(S[i])
    for i in range(t+1):
        if S[i+t] != ans[i]:
            c += 1
    print(c)

Measured memory_bytes: 3064
N = int(input())
list = map(int, input().split(" "))

numbers = []
for i in list:
    j = 1
    while j > 0:
        if i % 2**j == 0:
            j = j + 1
        else:
            break
    t = j - 1
    numbers.append(t)
    
print(min(numbers))

Measured memory_bytes: 38640