akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define vMAX 10001
#define INF (1<<30)
#define min(a,b) (a<b? a:b)
int n;

int A[1000],B[1000],L[550],R[550],sortedPos[vMAX], visited[1000];

//{{{ merge
void merge(int* A, int l, int mid, int r){
	int n1,n2,i,j,k;
	n1=mid-l;	n2=r-mid;
	for(i=0;i<n1;i++){
		L[i]=A[l+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=R[n2]=INF;

	i=j=0;
	for(k=l;k<r;k++){
		if(L[i]<=R[j]){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
		}
	}
}

void MergeSort(int* A, int l, int r){
	int mid;
	if(r-l>1){
		mid=(l+r)/2;
		MergeSort(A,l,mid);
		MergeSort(A,mid,r);
		merge(A,l,mid,r);
	}
}

//}}}

int main(){
	int i,now,sum,cnt,m,smallest=INF,ans=0;
	for(i=0;i<vMAX;i++)sortedPos[vMAX]=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
		smallest=min(A[i],smallest);
		B[i]=A[i];
	}
	MergeSort(B,0,n);
	for(i=0;i<n;i++){
		sortedPos[B[i]]=i;
	}

	
	for(int i=0;i<n;i++){
		now=i;	sum=0;	cnt=0;	m=INF;
		if(visited[now])continue;
		while(1){
			//printf("%d->",A[now]);
			visited[now]=1;
			sum+=A[now];	cnt++;
			m=min(m,A[now]);

			now=sortedPos[A[now]];
			if(visited[now])break;
		}
		//printf("\n");
		/*
			A:sum+(cnt-2)*m

			B:sum+(cnt-2)*m
				+2*(smallest+m)
					-(cnt-1)(m-smallest)

				=sum+(cnt+1)*smallest + m
		*/
		ans+=min(sum+(cnt-2)*m, sum+(cnt+1)*smallest+m);
	}

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

	return 0;
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<ld> Point;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

long modpow(long m, long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % MOD;
    else {
        long res = modpow(m, p / 2);
        return res * res % MOD;
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    mint ans = 0;
    rep(i, n) cin >> a[i];
    rep(i, 60) {
        ll cnt_zero = 0;
        ll cnt_one = 0;
        rep(j, n) {
            if ((a[j] >> i) & 1)
                cnt_one++;
            else
                cnt_zero++;
        }
        ans += (cnt_one * cnt_zero) % MOD * modpow(2, i);
    }
    out(ans.value);
    return 0;
}


Measured memory_bytes: 2560
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let h: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let c = |x: i64| {
        let mut cnt = 0;
        for i in 0..h.len() {
            cnt += std::cmp::max(0, h[i] - b * x + a - b - 1) / (a - b);
        }
        cnt <= x
    };

    let mut ok = 1i64 << 30;
    let mut ng = 0;
    while ok - ng > 1 {
        let mid = (ok + ng) >> 1;
        if c(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 6396
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
    var n = readLine.split(" ").map(_.toInt)

    while( n(0) != 0 || n(1) != 0) {
      for(i <- 0 to n(0)-1) {
        val str =  "#."*n(1)
        if(i%2==0)
          println(str.take(n(1)))
        else
          println(str.drop(1).take(n(1)))
      }
      println()
      n = readLine.split(" ").map(_.toInt)
    }
  }
}

Measured memory_bytes: 45700
###
### atcorder test program
###

import sys

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

math = math()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

N, K = [int(x) for x in input().split()]
S = input()

K -= 1

print(S[:K],end="")
print(S[K:K+1].lower(),end="")
print(S[K+1:])


Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=605;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int flag[MAXN][MAXN],n;
void solve(int n,int x)
{
	int num=0;
	while (!(x&3)) x>>=2,num++;
	if ((x&3)==1)
	{
		for (int i=0;i<n<<1;i++)
			for (int j=0;j<n<<1;j++) 
				if (((i>>num)&1)^((j>>num)&1)) flag[i][j]=1;
	}
	else
	{
		for (int i=0;i<n<<1;i++)
			for (int j=0;j<n<<1;j++) 
				if ((i>>num)&1) flag[i][j]=1;
	}
}
int main()
{
	int n=read(),dis1=read(),dis2=read();
	solve(n,dis1),solve(n,dis2);
	int num=0;
	for (int i=0;i<n<<1;i++)
	{
		for (int j=0;j<n<<1;j++)
		if (!flag[i][j])
		{
			printf("%d %d\n",i,j);
			++num;
			if (num==n*n) break;
		}
		if (num==n*n) break;
	}
	return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int d,t,s;
	std::cin >> d >> t >> s;
	std::cout << ((d>t*s)?"No":"Yes") << std::endl;
	return 0;
}


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

typedef long long ll;

const int maxn = 20005;

int n;
int a[maxn], b[maxn], p[maxn];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
	scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++)
    {
	a[i] = i * 20001;
	b[i] = (n - i + 1) * 20001;
    }
    for(int i = 1; i <= n; i++)
    {
	int last = a[p[i - 1]] + b[p[i - 1]];
	int dt = last - (a[p[i]] + b[p[i]]);
	if(dt >= 0)
	    b[p[i]] += dt + 1;
    }
    for(int i = 1; i <= n; i++)
	printf("%d ", a[i]);
    puts("");
    for(int i = 1; i <= n; i++)
    printf("%d ", b[i]);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    string S;
    cin >> S;
    long long int value = 922337203685477580;
    for(int i = 0; i < S.length()-2; i++) {
        long long int tmp =  abs(753-((int(S[i])-48)*100 + (int(S[i+1]) - 48)*10 + int(S[i+2])-48));
        if(value > tmp) value = tmp;
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
class Node:
    def __init__(self,key):
        self.key = key
        self.prev = None
        self.next = None

class DoublyLinkedList:
    def __init__(self):
        self.nil = Node(None)
        self.nil.prev = self.nil
        self.nil.next = self.nil
    
    def insert(self,key):
        new = Node(key)
        new.next = self.nil.next
        self.nil.next.prev = new
        self.nil.next = new
        new.prev = self.nil
    
    def listSearch(self,key):
        cur = self.nil.next
        while cur != self.nil and cur.key != key:
            cur = cur.next
        return cur
    
    def deleteNode(self, t):
        if t == self.nil:
            return
        t.prev.next = t.next
        t.next.prev = t.prev

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, key):
        self.deleteNode(self.listSearch(key))
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = DoublyLinkedList()
    for _ in range(n):
        c = input().rstrip()
        if c[0] == "i":
            d.insert(c[7:])
        elif c[6] == "F":
            d.deleteFirst()
        elif c[6] =="L":
            d.deleteLast()
        else:
            d.deleteKey(c[7:])
    ans = []
    cur = d.nil.next
    while cur != d.nil:
        ans.append(cur.key)
        cur = cur.next
    print(" ".join(ans))


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    if (s <= "2019/04/30")
        OP("Heisei");
    else
        OP("TBD");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
typedef long long LL;
using namespace std;

const LL mod = 1e9 + 7;
const int MAXN = 1e3 + 10;
int a[MAXN];

int main() {
	int n, sum = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	int k, y, x;
	scanf("%d", &k);
	for(int i = 0; i < k; ++i) {
		scanf("%d %d", &x, &y);
		printf("%d\n", sum - a[x] + y);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

int N, M; cin >> N >> M;
VVI xyz(N, VI(3));
vector<pair<i64, VI>> sum;
rep(i, 0, N) cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];

i64 maxi = 0;
rep(bit, 0, 1<<3){
    VI sum(N, 0);
    rep(j, 0, N) 
        rep(i, 0, 3){
            if (bit & (1<<i)) sum[j] += xyz[j][i];
            else sum[j] -= xyz[j][i];
        }
    sort(ALL(sum), greater<i64>());
    maxi = max(maxi, accumulate(RANGE(sum, 0, M), (i64)0));
}


cout << maxi << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] q) {
		try(Scanner sc = new Scanner(System.in)){
			while(true){
				int n = sc.nextInt(), s = sc.nextInt();
				if(n == 0 && s == 0) break;
				System.out.println(dfs(0, 0, s, n));
			}
		}
	}

	public static int dfs(int total, int addv, int target, int n){
		return n == 0 ? total == target ? 1 : 0 : addv > 9 ? 0 : dfs(total + addv, addv + 1, target, n - 1) + dfs(total, addv + 1, target, n);
	}

}

Measured memory_bytes: 26284
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
int main()
{
    int k;
    int  a,b;
    bool st=1;
    cin>>k;
    cin>>a>>b;
    for(int i=1;;i++)
    {
    	if(k*i>=a&&k*i<=b)
    	{
    		cout<<"OK";
    		st=0;
    		break;
		}
		if(k*i>b) break;
	}
	if(st==1) cout<<"NG";
    
    
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    int a, b;
    char c;
    cin >> a >> c >> b;
    if(c=='+') cout << a+b << endl;
    else cout << a-b << endl;
    
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    map<int, int> cnt;

    rep(i, N) {
        int A; cin >> A;
        cnt[A]++;
    }

    priority_queue<ll> Q;

    for (auto p : cnt) {
        // DUMP2(p.first, p.second);
        if (p.second >= 4) {
            Q.push(p.first);
            Q.push(p.first);
        } else if (p.second >= 2) {
            Q.push(p.first);
        }
    }

    if (Q.size() < 2) {
        cout << 0 << endl;
    } else {
        ll mx1 = Q.top(); Q.pop();
        ll mx2 = Q.top(); Q.pop();
        cout << mx1 * mx2 << endl;
    }
}

Measured memory_bytes: 4992
def make_ps(n):
    nums = [True] * n
    nums[0] = nums[1] = False
    p = 2
    sqrt = n ** 0.5
    while p < sqrt:
        for i in range(2 * p, n, p):
            nums[i] = False
        while True:
            p += 1
            if nums[p]:
                break
    return [i for i in range(n) if nums[i]]
ps = make_ps(105000)
while True:
    n = int(input())
    if not n:
        break
    print(sum(ps[:n]))

Measured memory_bytes: 8564
#include "bits/stdc++.h"
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

//u?????£??\??????v?????????????????????
int next(int u){
	for (int v = nt[u]; v < n; ++v) {
		nt[u]=v+1;
		if(M[u][v])return v;
	}
	return -1;
}

//?????????????????¨????????±???????????¢?´¢
void dfs_visit(int r){
	for (int i = 0; i < n; ++i) {nt[i]=0;}
	stack<int> S;
	S.push(r);
	color[r]=GRAY;
	d[r]=++tt;
	while(!S.empty()){
		int u=S.top();
		int v=next(u);
		if(v!=-1){
			if(color[v]==WHITE){
				color[v]=GRAY;
				d[v]=++tt;
				S.push(v);
			}
		}else{
			S.pop();
			color[u]=BLACK;
			f[u]=++tt;
		}
	}
}

void dfs(){
	//?????????
	for (int i = 0; i < n; ++i) {
		color[i]=WHITE;
		nt[i]=0;
	}
	tt=0;
	//????¨???????u????§??????¨????????±???????????¢?´¢
	for (int u = 0; u < n; ++u) {
		if(color[u]==WHITE)dfs_visit(u);
	}
	for (int i = 0; i < n; ++i) {
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
}


int main(){
	int u,k,v;
	cin>>n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			M[i][j]=0;
		}
	}
	for (int i = 0; i < n; ++i) {
		cin>>u>>k;
		u--;
		for (int j = 0; j < k; ++j) {
			cin>>v;
			v--;
			M[u][v]=1;
		}
	}
	dfs();
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

using ll = long long;

const int INF = 1001001001;
int n, a, b;
vector<int> h(100005);

// 二分探索用判定関数
bool C(int num){
    vector<int> temp(h.begin(), h.begin() + n);
    
    ll res = 0;
    ll subtraction = b * num;
    for(int i = 0; i < n; ++i){
        if(h[i] > subtraction){
            res += ceil((double)(h[i]-subtraction) / (a-b));
        }
    }
    
    return res <= num;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> a >> b;
    for(int i = 0; i < n; ++i){
        cin >> h[i];
    }
    
    int lb = -1, ub = ceil((double)*max_element(h.begin(), h.begin() + n) / b);
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(C(mid))      ub = mid;
        else            lb = mid;
    }
    
    cout << ub << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
long long Pow(long long X,long long K)
{
	long long i,S=1;
	for(i=1;i<=K;i++)S*=X;
	return S;
}
int main()
{
	long long N,K,Ans;
	scanf("%lld%lld",&N,&K);
	Ans=Pow(N/K,3);//a,b,cÎªKµÄ±¶Êý 
	if(K%2==0)Ans+=Pow((N+K/2)/K,3);//a,b,cÎªK/2+KµÄ±¶Êý 
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

int main() {
    int N,M;
    scanf("%d %d",&N,&M);
    long long int b,c;
    vector<long long int> A(N);
    vector<pair<long long int, long long int> > BC; 
    int i,j=0,k;
    for(i=0;i<N;i++){
        scanf("%lld",&A[i]);
    }
    for(j=0;j<M;j++){
        scanf("%lld %lld",&b,&c);
        BC.push_back(make_pair(c,b));
    }

    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end(),greater<pair<long long int,long long int> >());
    int f=0;
    int pi=0;
    j=0;
    while(j < M && f==0){
        k=BC[j].second -1 + pi;
        if(k>N) k=N-1;
        while(A[k] > BC[j].first){
            if(k!=0) k--;
            else {
                f = 1;
                break;
            }
        }
        if (f==1) break;
        for(int l=pi;l<=k;l++) {
            A[l] = BC[j].first;
        }
        pi = k + 1;
        j++;
    }

    long long int res=0;
    for(i=0;i<N;i++) {
        res += A[i];
    }
    printf("%lld",res);

    return 0;

}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int c=a+b;
if(c<10)
cout<<c;
else
cout<<"error";
system("pause");
return 0;
}

Measured memory_bytes: 504
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>

using namespace std;

typedef long long int lo;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (int)1e9
#define N (int)1e5 * 5
#define mod (int)1e9 + 7
#define all(x) (x).begin(), (x).end()
int in(){
    int a;
    cin >> a;
    return a;
}
int gcd(int a, int b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

void solve(){
    lo n;
    cin >> n;
    lo sum = 1;
    vector <lo> a(n);
    for(lo i = 0 ; i < n ; i++){
    	cin >> a[i];
    	if(a[i] == 0){
    		cout << 0 << endl;
    		return;
    	}
    }
    for(lo i = 0 ; i < n ; i++){
    	if(a[i] <= (lo)1e18 / sum){
    		sum *= a[i];
    	}
    	else{
    		cout << -1 << endl;
    		return;
    	}
    }
    cout << sum << endl;
}

int main(){
    // freopen("gir.gir", "r", stdin);
    // freopen("cik.cik", "w", stdout);
    fast
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
/*

*/


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

int main() {
    int N,ans=0;
    cin >> N;
    for (int i = 105; i <= N; i+=2) {
        int num_i = 0;
        for (int j = 1; j < sqrt(i); j++) {
            if (i%j==0 && j!=i%j) {
                num_i += 2;
            }
            else if (i%j==0 && j==i%j) {
                num_i++;
            }
        }
        if (num_i == 8) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//コンソールに入力した値を取得
		String a = sc.next();

		if(a.matches("[A-Z]+")) {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
		sc.close();
	}
}


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

int main() {
    int n, k; cin >> n >> k;
    vector<int> numcnts(n + 1, 0);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        numcnts[a]++;
    }
    sort(numcnts.rbegin(), numcnts.rend());
    for (int i = n; numcnts[i] <= 0; i--) numcnts.pop_back();

    int over = numcnts.size() - k;
    if (over <= 0) {
        cout << 0 << endl;
    } else {
        int ans = 0;
        for (int i = numcnts.size() - 1; over > 0; i--) {
            ans += numcnts[i]; over--;
        }

        cout << ans << endl;
    }
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  
  int n, k;
  string s;
  cin >> n >> k >> s;

  int ans = 0;
  rep(i, n-1) {
    if (s[i] == s[i+1]) ans++;
  }
  ans = min(ans + 2 * k, n - 1);
  cout << ans << endl;
  return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MOD = 1000000007;

int N;
int a[100010];

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

	bool ok = 1;
	int now, pt = N & 1;

	if (N & 1) {
		if (a[0]) ok = 0;
		now = 2;
	} else {
		now = 1;
	}

	for (; pt < N; pt += 2, now += 2) {
		if (a[pt] != now || a[pt+1] != now) {
			ok = 0;
		}
	}

	int ret = 1;
	rep(i, N/2) ret = ret * 2 % MOD;

	if (!ok) puts("0");
	else cout << ret << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
bool judge(int x){
    for(int i=0;i*i<=x;i++){
        if(i*i==x)return true;
    }
    return false;    
}
signed main(void){
    int n,d;cin>>n>>d;
    int V[n][d];
    rep(i,n)rep(j,d)cin>>V[i][j];
    int ans=0;
    rep(i,n)for(int j=i+1;j<n;j++){
        int x=0;
        rep(k,d){
            x+=(V[i][k]-V[j][k])*(V[i][k]-V[j][k]);
        }
        if(judge(x))ans++;
    }
    cout<<ans<<endl;
    
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

const int MAX_N = 2000000;
ll inv[MAX_N], fac[MAX_N], fiv[MAX_N];
void COMinit() {
    inv[1] = fac[1] = fiv[1] = inv[0] = fac[0] = fiv[0] = 1;
    for (ll i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
        fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
    }
}
ll com(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * fiv[k] % MOD * fiv[n-k] % MOD;
}

ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}

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

    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    COMinit();

    a = a * inv[100] % MOD;
    b = b * inv[100] % MOD;
    c = c * inv[100] % MOD;

    ll ret = 0;

    for (ll i = 0; i < n; i++) {
        ll tmp = com(n+i-1, i) * pow_mod(a, n, MOD) % MOD * pow_mod(b, i, MOD) % MOD;
        tmp = tmp * pow_mod(pow_mod(a + b, n + i, MOD), MOD - 2, MOD) % MOD;
        ret += (n+i) * pow_mod(a+b, MOD - 2, MOD) % MOD * tmp % MOD;
        ret %= MOD;
    }

    for (ll i = 0; i < n; i++) {
        ll tmp = com(n+i-1, i) * pow_mod(b, n, MOD) % MOD * pow_mod(a, i, MOD) % MOD;
        tmp = tmp * pow_mod(pow_mod(a + b, n + i, MOD), MOD - 2, MOD) % MOD;
        ret += (n+i) * pow_mod(a+b, MOD - 2, MOD) % MOD * tmp % MOD;
        ret %= MOD;
    }

    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 47736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n,t; cin >>n>>t;
    vector<int> a(n); rep(i,n) cin >> a[i];

    vector<int> profit(n);
    int mn = INF;
    for (int i = 0; i < n; i++) {
        mn = min(mn, a[i]);
        profit[i] = a[i] - mn;
    }

    sort(profit.begin(), profit.end(), greater<int>());

    int ans = 1;
    int mp = profit[0];
    for (int i = 1; i < n; i++) {
        if (profit[i] == mp) {
            ans++;
        } else {
            break;
        } 
    }

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


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

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


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    while(true){
        int n; cin >> n;
        if(!n) break;
        vector<long long> dp(n+1);
        dp[0]=1;
        for(int i=1; i<=n; ++i){
            if(i-3>=0) dp[i]+=dp[i-3];
            if(i-2>=0) dp[i]+=dp[i-2];
            if(i-1>=0) dp[i]+=dp[i-1];
        }
        long long tmp=(dp[n]+10-1)/10;
        cout << (tmp+365-1)/365 << endl;
    }
    return 0;
}




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
static const int INF = 2000000000;
static const int NIL = -1;
static const int MOD = 1000000007;
typedef long long ll;
typedef pair<int,int> P;
//#define int ll 

static const int MAX_N = 100;
static const int MAX_W = 10000;

int n,maxw;
int dp[MAX_N+1][MAX_W+1];
int w[MAX_N],v[MAX_N];

void solve(){
    for(int i=0;i<n;i++){
        for(int k=0;k<=maxw;k++){
            if(k<w[i]) dp[i+1][k] = dp[i][k];
            else dp[i+1][k] = max(dp[i][k],dp[i][k-w[i]]+v[i]);
        }
    }
    printf("%d\n",dp[n][maxw]);
}

signed main(){
    scanf("%d %d",&n,&maxw);
    for(int i=0;i<n;i++) scanf("%d %d",&v[i],&w[i]);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<=n;i++) dp[i][0] = 0;
    for(int i=0;i<=MAX_W;i++) dp[0][i] = 0;
    solve();
}

Measured memory_bytes: 7140
#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);
    a.at(i)--;
  }

  int i = 0, ans = 0;
  vector<bool> b(N, false);
  while (true) {
    ans++;
    b.at(i) = true;
    i = a.at(i);
    if (i == 1) {
      cout << ans << endl;
      return 0;
    }
    if (b.at(i)) {
      cout << -1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy = sum(B)
for i in range(0, N-1):
  if A[i]+1 == A[i+1]:
    satisfy += C[A[i]-1]
    
print(satisfy)

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double

using namespace std;

int n;
int a[100100];
int cnt[10];
int b;
int cur = 0;
int mn, mx;

int main() {
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	

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


	for(int i = 1; i <= n; i++) {			
		if(a[i] >= 1 && a[i] <= 399) {
			cnt[0]++;
		} else if(a[i] >= 400 && a[i] <= 799) {
			cnt[1]++;
		} else if(a[i] >= 800 && a[i] <= 1199) {
			cnt[2]++;
		} else if(a[i] >= 1200 && a[i] <= 1599) {
			cnt[3]++;
		} else if(a[i] >= 1600 &&  a[i] <= 1999) {
			cnt[4]++;
		} else if(a[i] >= 2000 && a[i] <= 2399) {
			cnt[5]++;
		} else if(a[i] >= 2400 && a[i] <= 2799) {
			cnt[6]++;
		} else if(a[i] >= 2800 && a[i] <= 3199) {
			cnt[7]++;
		} else {
			b++;
		}
	}

	for(int i = 0; i <= 7; i++) {
		if(cnt[i]) cur++;
	}

	mx = cur + b;
	mn = max(1, cur);

	cout << mn << " " << mx;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int N;
    cin >> N;
    vector<int> X(N);
    REP(i, N) cin >> X[i];
    int min = 1e9;
    FOR(i, 1, 101) {
        int tmp = 0;
        REP(j, N) {
            tmp += (i-X[j])*(i-X[j]);
        }
        if(tmp < min) min = tmp;
    }
    cout << min << endl;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int n;
vint a,b1,b2;

int main(){
  cin >> n; a.resize(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(i%2==0) b1.push_back(a[i]);
    else b2.push_back(a[i]);
  }
  if(n%2==0){
  rep(i,n/2) cout << b2[n/2-1-i] << ' ';
  for(auto x: b1) cout << x << ' ';
  }
  else{
    rep(i,n/2+1) cout << b1[n/2-i] << ' ';
    for(auto x:b2) cout << x << ' ';
  }
  cout << endl;

  return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ncopy = N;
            var sum = 0;
            while (Ncopy > 0)
            {
                sum += Ncopy % 10;
                Ncopy /= 10;
            }
            Console.WriteLine(N % sum == 0 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

ll a, b, c, n, k, x;
string s;

int main()
{
  cin >> n;
  int tm;
  vector<ll> a;
  for (ll i = 0; i < n; i++)
  {
    cin >> tm;
    a.push_back(tm);
  }

  sort(a.begin(), a.end(), greater<int>());

  ll ans = 0;
  for (ll i = 0; i < n; i++)
  {
    ans += a[i] * (i % 2 == 0 ? 1 : -1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int a, b;
  cin >> a >> b;
  int m = min(a, b);
  int M = max(a, b);
  while (M%m!=0) {
    int l = m;
    m = M%m;
    M = l;
  }
  ll ab = a;
  ab *= b;
  ab /= m;
  printf("%lld\n", ab);
} 


Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))
MOD=10**9+7

facN_1=1
suminv=[1]*N
inv=[1]*N
for i in range(2,N):
    facN_1=facN_1*i%MOD
    inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
    suminv[i]=(suminv[i-1]+inv[i])%MOD

ans=0
for i in range(N-1):
    tmp=X[i+1]-X[i]
    tmp*=suminv[i+1]%MOD
    ans+=tmp
    ans%=MOD
print(ans*facN_1%MOD)


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        long h = in.nl(), w = in.nl();
        int n = in.ni();
        int[] dx = new int[]{0,0,1,1,1,0,-1,-1,-1};
        int[] dy = new int[]{0,1,1,0,-1,-1,-1,0,1};
        HashMap<Point, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = in.ni(), b = in.ni();
            for (int j = 0; j < 9; j++) {
                if(a+dx[j]<=1||a+dx[j]>=h||b+dy[j]<=1||b+dy[j]>=w) continue;
                Point p = new Point(a+dx[j], b+dy[j]);
                map.put(p, map.containsKey(p)?map.get(p)+1:1);
            }
        }
        long[] ans = new long[10];
        for(Point p: map.keySet()) ans[map.get(p)]++;
        ans[0] = (h-2)*(w-2)-map.size();
        for(long l: ans) out.println(l);
    }
    public static class Point{
        int x, y;
        public Point(int x, int y){
            this.x = x; this.y = y;
        }
        @Override
        public boolean equals(Object o){
            return ((Point)o).x==x&&((Point)o).y==y;
        }
        @Override
        public int hashCode(){
            long res = 17;
            res *= x;
            res %= mod;
            res *= y;
            res %= mod;
            return (int)res;
        }
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 116764
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    queue = deque(range(1, 10))
    for _ in range(K):
        n = queue.popleft()

        tail = n % 10
        n10 = n * 10
        if tail != 0:
            queue.append(n10 + tail - 1)
        queue.append(n10 + tail)
        if tail != 9:
            queue.append(n10 + tail + 1)

    print(n)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74360
#include <stdio.h>

int main() {
  long long a, b, c;
  scanf("%lld %lld %lld", &a, &b, &c);
  
  int ret = 0;
  for (int i = 0; i < 1000000; i++) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      printf("%d\n", i);
      return 0;
    }

    long long na, nb, nc;
    na = (a + b) / 2;
    nb = (b + c) / 2;
    nc = (c + a) / 2;
    a = na; b = nb; c = nc;
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 128