akhauriyash/Code-Regression huggingface dataset:
N, M = list(map(int, input().split(" ")))
list_p = [0 for i in range(N)]
list_penalty = [0 for i in range(N)]
while(True) :
  try :
    temp = input()
    p, S = temp.split(" ")
    p = int(p)
    if(S == "AC") :
      list_p[p-1] = 1
    else :
      if(list_p[p-1] == 0) :
        list_penalty[p-1] += 1
  except EOFError :
    break

penalty=0
for i in range(N) :
  if(list_p[i] == 1) :
    penalty += list_penalty[i]
print(sum(list_p), penalty)

Measured memory_bytes: 4760
x=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n=int(input())-1
print(x[n])

Measured memory_bytes: 3060
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
u = [0]*n
v = [0]*n
for i in range(n):
    x, y = map(int, input().split())
    u[i] = x+y
    v[i] = x-y

ret = 0
ret = max(ret, max(u)-min(u))
ret = max(ret, max(v)-min(v))
print(ret)

Measured memory_bytes: 24496
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

#define fst first
#define scd second
#define rep(i,x) for(int i=0;i<(x);++i)

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

const int inf = 1e9;

int k[150];
vector<pii> stone[150];
int N, M;

int memo[150][150][10];

int rec(int n, int m, int i)
{
	if (n >= N - 1) return 0;

	if (~memo[n][m][i]) return memo[n][m][i];

	int res = inf;

	rep(j, k[n + 1]) {
		int dist = (stone[n][i].scd + stone[n + 1][j].scd) * abs(stone[n][i].fst - stone[n + 1][j].fst);
		chmin(res, dist + rec(n + 1, m, j));
	}

	if (m < M) {
		if (n + 2 >= N) return 0;
		rep(j, k[n + 2]) {
			int dist = (stone[n][i].scd + stone[n + 2][j].scd) * abs(stone[n][i].fst - stone[n + 2][j].fst);
			chmin(res, dist + rec(n + 2, m + 1, j));
		}
	}

	return memo[n][m][i] = res;
}

signed main()
{
	while (scanf("%d %d", &N, &M), N || M) {
		rep(i, N) {
			scanf("%d", &k[i]);

			stone[i].resize(k[i]);

			rep(j, k[i]) {
				int x, d; scanf("%d %d", &x, &d);
				stone[i][j].fst = x, stone[i][j].scd = d;
			}
		}

		int ans = inf;

		rep(i, k[0]) {
			memset(memo, -1, sizeof(memo));
			chmin(ans, rec(0, 0, i));
		}

		if (M > 0) {
			rep(i, k[1]) {
				memset(memo, -1, sizeof(memo));
				chmin(ans, rec(1, 1, i));
			}
		}

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

Measured memory_bytes: 1952
class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N = int(input())
S = list(input())
Q = int(input())

trees = [BIT(5 * 10 ** 5 + 2) for _ in range(26)]
for i in range(N):
    trees[ord(S[i]) - ord("a")].add(i + 1, 1)

for _ in range(Q):
    s, *x = input().split()
    if s == "1":
        i = int(x[0])
        c = x[1]
        trees[ord(S[i - 1]) - ord("a")].add(i, -1)
        trees[ord(c) - ord("a")].add(i, 1)
        S[i - 1] = c
    else:
        l, r = map(int, x)
        cnt = 0
        for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
        print(cnt)


Measured memory_bytes: 207168
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 20


int main() {
	int a[N];
	int b[N];
	int c[N];
	int d[N];
	long long ans[N];
	vector<int>aa;
	vector<int>bb;
	f(i, N)ans[i] = 1000000000000000000;
	int n, k;
	int x, y, z;
	int l, r, m;
	int cnt;
	vector<pair<int, int> >aaa;
	vector<pair<int, int> >bbb;
	int aaaa[N];
	int bbbb[N];
	int aaaaa[100000][N];
	int bbbbb[100000][N];
	int aaaaaa;
	int bbbbbb;
	int xa, xb, sz;
	long long s, xx, yy;
	scanf("%d", &n);
	k = 1;
	f(i, n)k = k * 3;
	f(i, n) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		aaa.push_back(make_pair(a[i], i));
		bbb.push_back(make_pair(b[i], i));
	}
	sort(aaa.begin(), aaa.end());
	sort(bbb.begin(), bbb.end());
	f(i, k) {
		x = i;
		cnt = 0;
		aa.clear();
		bb.clear();
		aa.push_back(0);
		bb.push_back(0);
		aaaaaa = 0;
		bbbbbb = 0;
		f(j, n) {
			d[j] = x % 3;
			if (d[j] > 0)cnt++;
			x /= 3;
			aaaaaa *= 2;
			bbbbbb *= 2;
			if (d[j] == 1) {
				aa.push_back(a[j]);
				aaaaaa++;
			}
			if (d[j] == 2) {
				bb.push_back(b[j]);
				bbbbbb++;
			}
		}
		sort(aa.begin(), aa.end());
		sort(bb.begin(), bb.end());
		s = 0;
		if (aaaaa[aaaaaa][N - 1] == 0) {
			xa = 0;
			sz = aa.size();
			f(j, n) {
				while (xa < sz) {
					if (aaa[j].first > aa[xa])xa++;
					else break;
				}
				x = abs(aaa[j].first - aa[xa - 1]);
				if (xa < sz)x = min(x, abs(aaa[j].first - aa[xa]));
				aaaa[aaa[j].second] = x;
				aaaaa[aaaaaa][aaa[j].second] = x;
			}
			aaaaa[aaaaaa][N - 1] = 1;
		}

		if (bbbbb[bbbbbb][N - 1] == 0) {
			xb = 0;
			sz = bb.size();
			f(j, n) {
				while (xb < sz) {
					if (bbb[j].first > bb[xb])xb++;
					else break;
				}
				x = abs(bbb[j].first - bb[xb - 1]);
				if (xb < sz)x = min(x, abs(bbb[j].first - bb[xb]));
				bbbb[bbb[j].second] = x;
				bbbbb[bbbbbb][bbb[j].second] = x;
			}
			bbbbb[bbbbbb][N - 1] = 1;
		}
		f(j, n) {
			x = min(aaaaa[aaaaaa][j], bbbbb[bbbbbb][j]);
			xx = (long long)x;
			yy = (long long)c[j];
			s += (xx * yy);
		}
		ans[cnt] = min(s, ans[cnt]);
	}
	f(i, n + 1)printf("%lld\n", ans[i]);


	return 0;
}


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

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

signed main(){
	int k,x; cin>>k>>x;
	if(500*k>=x) cout << "Yes" << endl;
	else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (A, B): (Vec<usize>, Vec<usize>) = {
        let (mut A, mut B) = (vec![], vec![]);
        for _ in 0..M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            A.push(iter.next().unwrap().parse().unwrap());
            B.push(iter.next().unwrap().parse().unwrap());
        }
        (A, B)
    };
    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..M { G[A[i]].insert(B[i]); }
        G
    };

    const INF: usize = 1_000_000_000;
    fn f(i: usize, G: &Vec<std::collections::HashSet<usize>>, p: &mut Vec<usize>) -> (usize, usize) {
        for &j in &G[i] { if p[j] != 0 && p[j] != INF { return (i, j) } }
        for &j in &G[i] {
            if p[j] == 0 {
                p[j] = i;
                let (l, r) = f(j, G, p);
                if l != INF { return (l, r); }
            }
        }
        p[i] = INF;
        (INF, INF)
    }
    let mut p = vec![0; N + 1];
    let mut flag = true;
    for i in 1..(N + 1) {
        if p[i] == 0 {
            let (l, r) = f(i, &G, &mut p);
            if l != INF && flag {
                let mut j = l;
                let mut res = vec![];
                while j != r {
                    res.push(j);
                    j = p[j];
                }
                res.push(r);
                println!("{}\n{}",
                    res.len(),
                    res.iter().map(|r| r.to_string()).collect::<Vec<_>>().join("\n")
                );
                flag = false;
            }
        }
    }
    if flag {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>


using namespace std;
typedef long long ll;

int main(){
	int n, m, i, j, k;
	int a[111], b[111];
	char t[111];
	while(~scanf("%d %d %d", &n, &m, &k)){
		for(i = 0; i < k; i++){
			if(i % 2 == 0){
				if(n % 2 == 1){
					n -= 1;
					m += n / 2;
					n /= 2;
					continue;
				}
				if(n % 2 == 0){
					m += n / 2;
					n /= 2;
				}
			}
			if(i % 2 == 1){
				if(m % 2 == 1){
					m -= 1;
					n += m / 2;
					m /= 2;
					continue;
				}
				if(m % 2 == 0){
					n += m / 2;
					m /= 2;
				}
			}
		}
		printf("%d %d\n", n, m);
	}
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi a(n);
    bool same = true;
    bool x = true;
    rep(i, n) {
        cin >> a[i];
        if(i and a[i] != a[i-1]) same = false;
    }
    if(same) {
        if(a[0] == n-1 or a[0] <= n/2) x = true;
        else x = false;
    } else {
        int num = 0;
        int hg = a[0];
        rep(i, n) {
            hg = max(hg, a[i]);
        }
        rep(i, n) {
            if(hg != a[i] and hg != a[i]+1) {
                x = false;
            }
            if(hg == a[i]+1) {
                num++;
            }
        }

        hg -= num;
        if(hg <= 0) x = false;
        if(hg > (n-num)/2) x = false;
    }

    cout << (x ? "Yes":"No") << endl;


}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
int p,q,r;
scanf("%d%d%d",&p,&q,&r);
int num,sum,mum;
num=p+q;
sum=p+r;
mum=q+r;
if(num<=sum&&num<=mum){
    printf("%d\n",num);
}
else if(sum<=num&&sum<=mum){
    printf("%d\n",sum);
}
else if(mum<=num&&mum<=sum){
    printf("%d\n",mum);
}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<string> sA(N);
	for (int i = 0; i < N; ++i) { cin >> sA[i]; }

	vector<Int> A(N);
	vector<pair<int, int>> X(N);
	int n = 50;
	vector<vector<int>> d(n + 5, vector<int>(n + 5, 0));
	for (int i = 0; i < N; ++i) {
		int idx = sA[i].size();
		for (int j = 0; j < sA[i].size(); ++j) {
			if (sA[i][j] == '.') { idx = j; }
		}
		A[i] = stoi(sA[i].substr(0, idx++));
		for (int j = 0; j < 9; ++j) {
			A[i] *= 10;
			if (idx + j < sA[i].size()) {
				A[i] += sA[i][idx + j] - '0';
			}
		}

		int x2 = 0, x5 = 0;
		while (A[i] % 2 == 0) { A[i] /= 2; ++x2; }
		while (A[i] % 5 == 0) { A[i] /= 5; ++x5; }
		X[i] = { x2, x5 };
		++d[x2][x5];
	}
	for (int i = n; i >= 0; --i) {
		for (int j = n; j >= 0; --j) {
			d[i][j] += d[i + 1][j] + d[i][j + 1] - d[i + 1][j + 1];
		}
	}

	Int ans = 0;
	for (int i = 0; i < N; ++i) {
		int x2 = max(0, 18 - X[i].first);
		int x5 = max(0, 18 - X[i].second);
		ans += d[x2][x5];
		if (x2 <= 9 and x5 <= 9) { --ans; }
	}
	cout << ans / 2 << "\n";

	return 0;
}


Measured memory_bytes: 12668
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(NULL);
int main() 
{ 
  FASTIO;
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  if(s[0]==s[2]) cout<<"No"<<"\n";
  else cout<<"Yes"<<"\n";
  
    return 0; 
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int x[] = new int[N];
        int y[] = new int[N];
        int h[] = new int[N];
        for(int i = 0; i < N; i++){
            x[i] = scanner.nextInt();
            y[i] = scanner.nextInt();
            h[i] = scanner.nextInt();
        }

        for(int Cx = 0; Cx <= 100; Cx++){
            for(int Cy = 0; Cy <= 100; Cy++){
                int kh = -1;
                boolean f = false;
                for(int i = 0; i < N; i++){
                    if(h[i] > 0){
                        kh = h[i] + Math.abs(Cx - x[i]) + Math.abs(Cy -y[i]);
                        break;
                    }
                }
                for(int i = 0; i < N; i++){
                    int eh = Math.max(kh - Math.abs(x[i] - Cx) - Math.abs(y[i] - Cy), 0);
                    if(eh != h[i]){
                        f = true;
                        break;
                    }
                }

                if(f){
                    continue;
                }else{
                    System.out.printf("%d %d %d", Cx, Cy, kh);
                }
            }
        }

    }

}

Measured memory_bytes: 23508
#include <cstdio>
struct pos { int x, y; };
int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		int map[n][n];
		for (int i=0; i<n; i++) for (int j=0; j<n; j++) map[i][j] = -1;
		pos p; p.y = n/2; p.x = n/2+1;
		for (int i=1; i<=n*n; i++) {
			while (map[p.x][p.y] != -1) {
				p.x++; p.y--;
				if (p.x>=n) p.x = 0;
				else if (p.x<0) p.x = n-1;
				if (p.y>=n) p.y = 0;
				else if (p.y<0) p.y = n-1;
			}
			map[p.x][p.y] = i;
			p.x++; p.y++;
			if (p.x>=n) p.x = 0;
			else if (p.x<0) p.x = n-1;
			if (p.y>=n) p.y = 0;
			else if (p.y<0) p.y = n-1;
		}
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				printf("%4d", map[i][j]);
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Intersection of Rectangles
 */
public class Main {

	static Main main = new Main();

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);

			double xa1 = Double.parseDouble(st.nextToken());
			double ya1 = Double.parseDouble(st.nextToken());
			double xa2 = Double.parseDouble(st.nextToken());
			double ya2 = Double.parseDouble(st.nextToken());

			double xb1 = Double.parseDouble(st.nextToken());
			double yb1 = Double.parseDouble(st.nextToken());
			double xb2 = Double.parseDouble(st.nextToken());
			double yb2 = Double.parseDouble(st.nextToken());

			Rectangle r1 = main.new Rectangle(xa1, ya1, xa2, ya2);
			Rectangle r2 = main.new Rectangle(xb1, yb1, xb2, yb2);

			if (r1.intersect(r2)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}

		}

	}

	class Rectangle {

		double top, bottom, left, right;

		Rectangle(double... p) {
			left = p[0];
			bottom = p[1];
			right = p[2];
			top = p[3];
		}

		boolean intersect(Rectangle other) {
			if (intersect(this, other)) {
				return true;
			} else {
				return intersect(other, this);
			}
		}

		boolean intersect(Rectangle r1, Rectangle r2) {
			if (((r1.left <= r2.left && r2.left <= r1.right) || (r1.left <= r2.right && r2.right <= r1.right))
					&& ((r1.bottom <= r2.bottom && r2.bottom <= r1.top) || (r1.bottom <= r2.top && r2.top <= r1.top))) {
				return true;
			} else if ((r1.left <= r2.left && r2.right <= r1.right)
					&& (r2.bottom <= r1.bottom && r1.top <= r2.top)) {
				return true;
			} else if ((r2.left <= r1.left && r1.right <= r2.right)
					&& (r1.bottom <= r2.bottom && r2.top <= r1.top)) {
				return true;
			} else {
				return false;
			}
		}
	}

}

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

int main() {
  long long int N, MOD = 1000000007;
  cin >> N;
  vector<long long int> A(N);
  for (long long int i = 0; i < N; i++) cin >> A.at(i);
  long long int S1 = 0, S2 = 0;
  for (long long int i = 0; i < N; i++) {
    S1 = (S1 + A.at(i)) % MOD;
    S2 = (S2 + ((A.at(i) * A.at(i)) % MOD)) % MOD;
  }
  S1 = (S1 * S1) % MOD;
  long long int ans = (S1 - S2) % MOD;
  if (ans < 0) ans += MOD;
  long long int inv2 = MOD - (MOD / 2) % MOD;
  ans = (inv2 * ans) % MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
#include<cstdio>
#define MAX 200005
using namespace std;
long long nums[MAX]={0};
int val[MAX];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&val[i]);
		nums[val[i]]+=1;
	}
	long long sum=0;
	for(int i=1;i<=n;i++){
		if(nums[i]>=2){
			sum+= (nums[i]*(nums[i]-1))/2;
		}
	} 
	
	for(int k=0;k<n;k++){
		long long temp=sum;
		if(nums[val[k]]>=2){
			long long kNum=nums[val[k]];
			temp= temp -kNum*(kNum-1)/2+(kNum-1)*(kNum-2)/2;	
		}
		printf("%lld\n",temp);
	}
	return 0;
}

Measured memory_bytes: 3968
from heapq import heappush, heappop
n = input()
A = map(int, raw_input().split())
left = [None]*(3*n+1)
right = [None]*(3*n+1)
lsum = rsum = 0
que = []
for i in xrange(3*n):
    lsum += A[i]
    heappush(que, A[i])
    if len(que) > n:
        v = heappop(que)
        lsum -= v
    if len(que) == n:
        left[i] = lsum
que = []
for i in xrange(3*n-1, -1, -1):
    rsum += A[i]
    heappush(que, -A[i])
    if len(que) > n:
        v = heappop(que)
        rsum += v
    if len(que) == n:
        right[i] = rsum
ans = -10**18
for i in xrange(3*n):
    if left[i] is not None and right[i+1] is not None:
        ans = max(ans, left[i] - right[i+1])
print ans


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

int main()
{
    int n,r=0;
    cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++){
        cin>>p.at(i);
    }
    for(int i=1;i<n-1;i++){
        if(p.at(i-1)>p.at(i)&&p.at(i)>p.at(i+1)){
            r++;
        }else if(p.at(i-1)<p.at(i)&&p.at(i)<p.at(i+1)){
            r++;
        }
    }
    cout<<r<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int isPrime(int n);

int main(void)  {
	int i, n, x, num = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)  {
	scanf("%d", &x);
		isPrime(x);
  		if (isPrime(x) == 1)
   			num++;
	}
	printf("%d\n", num);
	return 0;
}

int isPrime(int x)  {
	int i;
	if (x == 2)
	 return 1;
 
	if (x < 2 || x % 2 == 0)  
	 return 0;
 
	i = 3;
	while (i <= (double)sqrt(x))  {
		if (x % i == 0)
			return 0;
		i = i + 2;
	}
		return 1;
	
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a[101], ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; i++) {
    i % 2 ? ans -= a[i] : ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define eps 1e-10
#define equals(a , b) (fabs((a) - (b)) < eps)

class Point
{
public:
    double x , y;

    Point(double x = 0 ,double y = 0):x(x) , y(y) {}

    Point operator +(Point p){return Point(x + p.x , y + p.y) ;}
    Point operator -(Point p){return Point(x - p.x , y - p.y) ;}
    Point operator *(double a){return Point(a * x , a * y) ;}
    Point operator /(double a){return Point(x / a , y / a) ;}

    double abs() {return sqrt(norm()) ;}
    double norm() {return x * x + y * y ;}

    bool operator < (const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y ;
    }

    bool operator == (const Point &p) const
    {
        return fabs(x - p.x) < eps && fabs(y - p.y) < eps ;
    }

};

typedef Point Vector;

struct Segment  //表示线段结构体
{
    Point p1 , p2 ;
};

double dot(Vector a , Vector b)  // 向量a,b的内积
{
    return a.x * b.x + a.y * b.y ;
}

double cross(Vector a, Vector b)  //向量a,b外积
{
	return a.x * b.y - a.y * b.x ;
}

bool isOrthogonal(Vector a , Vector b)  //判断是否正交
{
    return equals(dot(a , b) , 0.0) ;
}

bool isOrthogonal(Point a1 , Point a2 , Point b1 , Point b2)
{
    return isOrthogonal(a1 - a2 , b1 - b2) ;
}

bool  isOrthogonal(Segment s1 , Segment s2)
{
    return equals(dot(s1.p2 - s1.p1 , s2.p2 - s2.p1) , 0.0) ;
}

bool isParallel(Vector a, Vector b)  //判断是否平行
{
	return equals(cross(a, b), 0.0) ;
}

bool isParallel(Point a1, Point a2, Point b1, Point b2)
{
	return isParallel(a1 - a2, b1 - b2) ;
}

bool isParallel(Segment s1, Segment s2)
{
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0) ;
}

Point project(Segment s, Point p)  //p在s上的投影
{
    Point base = s.p2 - s.p1 ;
    double r = dot(p - s.p1 , base) / base.norm() ;
    return s.p1 +base * r ;
}
/*
求垂足x：对于给定的三点p1,p2,p从点p向通过p1,p2的直线引一条垂线
base=p2-p1;
hypo=p-p1;
 x=s.p1+base*(hypo*base/|base|^2); hypo*base 可以用向量内积求
*/

Point reflect(Segment s , Point p)
{
    return p + (project(s , p) - p) * 2.0 ;
}

int main()
{
    Point p1 , p2 ;
    cin >> p1.x >> p1.y >> p2.x >> p2.y ;
    int q ;
    Segment s ;
    s.p1 = p1 ;
    s.p2 = p2 ;
    cin >> q ;
    while(q --)
    {
        Point p ;
        cin >> p.x >> p.y ;
        Point w = reflect(s , p) ;
        printf("%.10lf %.10lf\n" , w.x , w.y) ;
    }
    return 0 ;
}



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }

  ll sum = 0;
  for (ll i = 0; i < n; ++i) {
    sum ^= a[i];
  }

  ll ans = 0;
  for (ll i = 0; i < n-1; ++i) {
    ans = sum ^ a[i];
    cout << ans << " ";
  }
  ans = sum ^ a[n-1];
  cout << ans <<  endl;

  return 0;
}


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

int main(void) {
  int n, k, a;
  cin >> n >> k;
  a = 0;
  vector<int> x(n);
 
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  
  sort(x.begin(), x.end());
  
  for (int i = 0; i < k; i++) {
    a += x.at(i);
  }
 
  cout << a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  int k, s; cin >> k >> s;
  for(int i = 0; i <= k; i++) for(int j = 0; j <= k && i + j <= s; j++) {
    if(i + j + k >= s) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[214514];
vector<int> g2[214514];
int par[214514],visited[214514],gr[214514],deg[214514];
bool iscycle[214514];
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		par[i]=x;
		nex[x].pb(i);
		deg[x]++;
	}
	bool fl = true;
	int cur = 1;
	while(fl){
		visited[cur]++;
		if( visited[cur] == 2 ){
			iscycle[cur]=true;
		}
		if( visited[cur] == 3 ){
			break;
		}
		cur = par[cur];
	}
	queue<int> que;
	for(int i=1;i<=n;i++){
		if( iscycle[i] == false && deg[i]==0 ){
			que.push(i);
		}
	}
	while(!que.empty()){
		int cur = que.front(); que.pop();
		int num = 0;
		set<int> st;
		for(int i=0;i<nex[cur].size();i++){
			st.insert(gr[nex[cur][i]]);
		}
		while( st.find(num) != st.end() ){
			num++;
		}
		gr[cur] = num;
		deg[ par[cur] ] --;
		if( deg[par[cur]]==0 )que.push(par[cur]);
	}
	int start = -1;
	for(int i=1;i<=n;i++){
		if( iscycle[i] == true ){
			start = i;
			set<int> st;
			int num=0;
			for(int j=0;j<nex[i].size();j++){
				if(!iscycle[nex[i][j]])st.insert( gr[ nex[i][j] ] );
			}
			while( g2[i].size() < 2 ){
				if( st.find(num) == st.end() ){
					g2[i].pb(num);
				}
				num++;
			}
			//cout<<i<<" "<<g2[i][0]<<" "<<g2[i][1]<<endl;
		}
	}
	cur = g2[start][0];
	int cx = start;
	while(1){
		int cp = par[cx];
		if( cp != start ){
			if( cur == g2[cp][0] ){
				cur = g2[cp][1];
				cx = cp;
			}
			else{
				cur = g2[cp][0];
				cx = cp;
			}
			//cout<<cp<<" "<<cur<<endl;
		}
		else{
			if( cur != g2[cp][0] ){
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
			break;
		}
	}
	cur = g2[start][1];
	cx = start;
	while(1){
		int cp = par[cx];
		if( cp != start ){
			if( cur == g2[cp][0] ){
				cur = g2[cp][1];
				cx = cp;
			}
			else{
				cur = g2[cp][0];
				cx = cp;
			}
			//cout<<cp<<" "<<cur<<endl;
		}
		else{
			if( cur == g2[cp][0] ){
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
			break;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 27520
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k;

string s;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string ans;
	cin>>s;
	for(int i=0;i<s.length();++i)
	{
		ans+='x';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<iomanip>
using namespace std;

int main(){
    int N; cin>>N;
    string S,T; cin>>S>>T;

    for(int i=0;i<N;i++){
        cout<<S[i]<<T[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
this_month = []
while (input = gets) && input != "\n"
  this_month << input.split(',').map(&:to_i).first
end

last_month = []
while input = gets
  last_month << input.split(',').map(&:to_i).first
end

targets = (this_month & last_month).sort
targets.each do |c|
  puts "#{c} #{this_month.count(c) + last_month.count(c)}"
end

Measured memory_bytes: 8600
from collections import deque
Sa = input()
Sb = input()
Sc = input()
a = deque(list(Sa))
b = deque(list(Sb))
c = deque(list(Sc))

x = 'a'
while True:
    if x == 'a':
        if not a:break
        x = a.popleft()
    elif x == 'b':
        if not b:break
        x = b.popleft()
    elif x == 'c':
        if not c:break
        x = c.popleft()
if x == 'a':
    print('A')
elif x == 'b':
    print('B')
else:
    print('C')

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N;
int a[212345];

int main() { 
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	REP(i, N) pq.push(pii(a[i], i));
	
	set<int> ss;
	ll ans = 0;
	while (!pq.empty()) {
		int x = pq.top().fi;
		int p = pq.top().se;
		pq.pop();
		
		int l, r;
		
		set<int>::iterator it = ss.lower_bound(p);
		
		if (it != ss.end()) r = *it;
		else r = N;
		
		if (ss.empty()) l = -1;
		else if (it == ss.end()) l = *(--ss.end());
		else if (it == ss.begin()) l = -1;
		else l = *(--it);
		
		ans += (ll)(r - p) * (p - l) * x;
		ss.insert(p);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
#define ll signed long long
ll x,y,a,b,c,d;
int main()
{
    scanf("%lld %lld %lld %lld",&a, &b, &c, &d);
    ll ans = max(a*c, b*c);
    ans = max(ans,a*d);
    ans = max(ans,b*d);
    cout << ans;
    return 0;
}

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

bool is_prime(int a){
  if(a<1) return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0) return false;
  }
  return true;
}

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());


  int X;
  cin>>X;

  while(X>0){
    if(is_prime(X)){
      cout<<X<<endl;
      return 0;
    }
    X++;
  }

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		List<int[]> list = new ArrayList<>();
		for(int i=0;i<m;i++) {
			int[] tmp = new int[3];
			tmp[0] = in.nextInt();
			tmp[1] = in.nextInt();
			tmp[2] = in.nextInt();
			list.add(tmp);
		}
		int[] uft = new int[n+1];
		for(int i=1;i<=n;i++) {
			uft[i] = i;
		}
		for(int i=0;i<list.size();i++) {
			int[] tmp = list.get(i);
			union(uft,tmp[0],tmp[1]);
		}
		boolean[] used = new boolean[n+1];
		int ans = 0;
		for(int i=1;i<=n;i++) {
			if(!used[find(uft,i)]) {
				used[find(uft,i)] = true;
				ans++;
			}
		}
		System.out.println(ans);
		

	}
	//return root node idx O(a(N)) ( O(1)<O(a(N))<O(logN) )
	public static int find(int[] tree,int idx) {
		if(tree[idx]==idx) return idx;
		else return tree[idx] = find(tree,tree[idx]);
	}
	
	//union idx2 tree to idx1 tree O(a(N))
	public static void union(int[] tree,int idx1,int idx2) {
		int root1 = find(tree,idx1);
		int root2 = find(tree,idx2);
		tree[root2] = root1;
	}

}


Measured memory_bytes: 95428
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int K, X;
  cin >> K >> X;
  for(int i = max(-1000000, X - K + 1); i <= min(1000000, X + K - 1); i++) {
    if(i ==  max(-1000000, X - K + 1)) cout << i;
    else cout << " " << i;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const int MAX= 4e5+6;
const ll inf =1e18;
 
 

string s,t[MAX];
map<char,ll> m;
int main(){
	fastio;
	ll n,a,b,c;
	cin>>n>>m['A']>>m['B']>>m['C'];
	vector<char> v;
	f(i,0,n) cin>>t[i];
	f(i,0,n){
		s=t[i];
		if(m[s[0]]<m[s[1]]) {
			m[s[0]]++,m[s[1]]--;
			v.push_back(s[0]);
		}
		else if(i==n-1 || m[s[0]]>m[s[1]]){
			m[s[0]]--,m[s[1]]++;
			v.push_back(s[1]);
		}
		else{
			if(s[0]==t[i+1][0] || s[0]==t[i+1][1]){
				m[s[0]]++,m[s[1]]--;
				v.push_back(s[0]);
			}
			else{
				m[s[0]]--,m[s[1]]++;
				v.push_back(s[1]);
			}
		}
		if(m[s[0]]==-1 || m[s[1]]==-1) {
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	f(i,0,n) cout<<v[i]<<endl;
	
}

Measured memory_bytes: 16272
import bisect as bi

nn=int(input())
A=list(map(int,input().split()))

A.sort()

n=A[nn-1]

ki=bi.bisect_right(A[:nn-1],float(n/2))
#print(ki)
if abs(float(n/2)-A[:nn-1][min(ki,nn-2)]) <= abs(float(n/2)-A[:nn-1][max(ki-1,0)]) :
    k=A[min(ki,nn-2)]
else :
    k=A[max(ki-1,0)]

print("{} {}".format(n,k))


Measured memory_bytes: 14056
let () =
  Scanf.scanf "%d\n"
    (fun n -> Array.init n (fun _ ->
         Scanf.scanf "%f %f %f %f %f %f %f %f\n"
           (fun x1 y1 x2 y2 x3 y3 x4 y4 ->
              if abs_float ((y2 -. y1)*.(x4 -. x3) -. (x2 -. x1)*.(y4 -. y3)) < 0.0000000001 then "YES\n" else "NO\n")))
  |> Array.fold_left (^) "" |> print_string


Measured memory_bytes: 2208
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

vector<int> visited;
void dfs(const vector<vector<int>>& T, vector<int>& counter, int depth)
{
    visited[depth] = 1;
    for(int i = 0; i < T[depth].size(); i++)
    {
        int v = T[depth][i];
        if(visited[v]) continue;
        counter[v] += counter[depth];
        dfs(T, counter, v);
    }
}

void solve()
{
    int n, q; cin >> n >> q;
    vector<vector<int>> T(n);
    visited.resize(n, 0);
    for(int i = 0; i < n - 1; i++)
    {
        int a, b; cin >> a >> b;
        a--, b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    vector<int> counter(n, 0);
    for(int i = 0; i < q; i++)
    {
        int p, x; cin >> p >> x;
        p--;
        counter[p] += x;
    }
    dfs(T, counter, 0);
    cout << counter << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string ara;
     cin>>ara;
    if(ara[0]=='S')
    {
        cout<<"Cloudy\n";
    }
   else if(ara[0]=='R')
    {
        cout<<"Sunny\n";
    }
    else
    {
         cout<<"Rainy\n";
    }
    return 0;
}



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

int main() {
  int H,W,N;
  cin >> H >> W >> N;

  int count=0;
  int result=0;

  while(count < N){
    if(H > W){
      count += H;
    }else{
      count += W;
    }
    result++;
  }

  cout << result << endl;
}


Measured memory_bytes: 256
s = input() #bit全探索
l = len(s) -1
n = 2**l
cnt = 0

for i in range(n):
    ls = []
    for j in range(l):
        if (n-i >> j) & 1:
            ls.append(j+1)
    ls.append(l+1)
    a = 0
    for z in ls:
        cnt += int(s[a:z])
        a = z
print(cnt)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int m = S % 3600 / 60;
		int s = S % 3600 % 60;

		System.out.println(h + ":" + m + ":" + s);
		sc.close();
	}

}


Measured memory_bytes: 26380
//file_name:ABC88_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    ll ans = 0;
    rep(i,n){
        if(n%2==0){
            if(i%2==0){
                ans-=a[i];
            }else{
                ans+=a[i];
            }
        }else{
            if(i%2==0){
                ans+=a[i];
            }else{
                ans-=a[i];
            }
        }
    }


    

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



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

int N, T;
const int MAX_N = 2.0e5 + 100;
int t[MAX_N];

int main() {
    cin >> N >> T;
    for (int i = 0; i < N; i++) cin >> t[i];

    ll ans = T;
    for (int i = 1; i < N; i++) {
        if (t[i] - t[i-1] < T) {
            ans += t[i] - t[i-1];
        }
        else {
            ans += T;
        }
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys

#tmp= int(input())
#tmp= float(input())
while(1):
    tmp = input().split()
#a,b = list(map(lambda a: int(a), tmp))

    a=int(tmp[0])
    b=int(tmp[2])
    op=tmp[1]

#print(a)
#print(op)
#print(b)
    if(op=="+"):
        print(a+b)
    if(op=="-"):
        print(a-b)
    if(op=="*"):
        print(a*b)
    if(op=="/"):
        print(a//b)
    if(op=="?"):
        sys.exit()



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

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define pb push_back
#define mp make_pair
#define SZ(a) ((int)(a.size()))
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> PI;


int h,w;
int cost[200][200];
int dp[1<<6][200];
int n;

int main(int argc, char *argv[])
{
  while(cin >> h >> w, h){
    n = h * w;
    rep(i,n)rep(j,n) cost[i][j] = 1e8;
    rep(i,n) cost[i][i] = 0;
    
    vector<int> ter;
    
    rep(i,h)rep(j,w){
      if(i+1 < h)
        cost[i*w+j][(i+1)*w+j] = cost[(i+1)*w+j][i*w+j] = 1;
      
      if(j+1 < w)
        cost[i*w+j][(i)*w+j+1] = cost[(i)*w+j+1][i*w+j] = 1;
      
      int  t;
      cin >> t;
      if(t) ter.pb(i*w+j);
    }
    
    rep(k,n)rep(i,n)rep(j,n)
      cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
    
    rep(i,1<<SZ(ter)) rep(j,n) dp[i][j] = 1e8;
    
    rep(i,SZ(ter))rep(j,n) dp[1<<i][j] = cost[ter[i]][j];
    
    // rep(i,n){
    //   rep(j,n){
    //     cout << cost[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    
    {
      for(int S = 0; S < (1<<SZ(ter)); ++S){
        if((S&(S-1)) == 0) continue;
        int sub = S-1;
        do{
          rep(i,n)
            dp[S][i] = min(dp[S][i], dp[sub][i] + dp[S^sub][i]);
          sub = S & (sub-1);
        }while(sub);
        rep(p,n)rep(q,n)
          dp[S][p] = min(dp[S][p],dp[S][q] + cost[q][p]);
      }
    }
    
    cout << n - dp[(1<<SZ(ter))-1][ter[0]] - 1 << endl;
  }
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    int n;
    cin >> n;
    typedef pair<int,int>  coordinate;
    vector<coordinate> red;
    vector<coordinate> blue;
    rep(i,n){
      int a,b;
      cin >> a >> b;
      coordinate tmp;
      tmp.first = a;
      tmp.second = b;
      red.push_back(tmp);
    }
    rep(i,n){
      int c,d;
      cin >> c >> d;
      coordinate tmp;
      tmp.first = c;
      tmp.second = d;
      blue.push_back(tmp);
    }
    int count = 0;
    sort(all(blue));
    int r_flag[100] = {0};
    rep(i,n){
      int c=blue[i].first;
      int d = blue[i].second;
      int idx = -1;
      int b=0;
      rep(j,n){
        if (!r_flag[j] && c>red[j].first && d > red[j].second&&b<=red[j].second){
            b = red[j].second;
            idx = j;
        }
      }
      if (idx != -1){
          r_flag[idx] = 1;
          count += 1;
      }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        int minval = 100;
        int maxval = 0;
        for(int i=0; i<N; i++) {
            X[i] = sc.nextInt();
            if(X[i]<minval) minval=X[i];
            if(X[i]>maxval) maxval=X[i];
        }
        long result = Long.MAX_VALUE;
        for(int i=minval; i<=maxval; i++) {
            long tmpsum = 0;
            for(int t=0; t<N; t++) {
                tmpsum += (X[t]-i)*(X[t]-i);
            }
            if(tmpsum<result) result=tmpsum;
        }
        System.out.println(result);
    }
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

struct UnionFind {
	vector<int> p, r;

	UnionFind() {}
	UnionFind(int size) { init(size); }

	void init(int size) {
		p.resize(size);
		r.resize(size);
		for (int i = 0; i < size; ++i) {
			p[i] = i; r[i] = 1;
		}
	}

	int find(int x) {
		if (p[x] == x) return x;
		else return p[x] = find(p[x]);
	}

	void unite(int x, int y) {
		x = find(x); y = find(y);

		if (x == y) return;

		if (r[x] > r[y]) swap(x, y);
		r[x] += r[y];
		p[y] = x;
	}

	bool is_root(int x) {
		return find(x) == x;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int element_count(int x) {
		x = find(x);
		return r[x];
	}
};

int main() {
	int n;

	while (cin >> n, n) {
		UnionFind uf(n * n);
		rep(i, n) rep(j, n) {
			int x = in(), y = in();
			
			int u = y * n + x;
			int v = i * n + j;

			uf.unite(u, v);
		}

		int ans = 0;
		bool f[10000] = {false};
		rep(i, n * n) {
			if (f[uf.find(i)]) continue;
			f[uf.find(i)] = true;
			ans++;
		}

		print(ans);
	}
}

Measured memory_bytes: 3096
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<limits>
#include<bitset>
#include<unordered_map>
#include<functional>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define Sort(a) sort(all(a))
#define Qsort(a,size) qsort(a,size,sizeof(*a),compare_int)
#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
bool compare_int(const void *a,const void *b) { return *(int *)a-*(int *)b; }
bool compare_by_second(II a,II b) { return a.second!=b.second?a.second<b.second:a.first<b.first; }

const int INF =1e+9;

ull l,k;

int main(int argc, char const *argv[]) {
  cin>>l>>k;
  ull black=0;
  ull cnt=0,cnt2=0;
  for(ull thi=1; thi<=l; thi+=2){
    black+=1;
    ull batu=0;
    //cout << thi << " " << black << endl;
    for(ull thi2=thi+k-1; thi2<=l && batu<black; thi2+=(k-1)){
      batu++;
    }
    //cout << black << " " << batu << endl;
    rep(i,0,batu+1){
      ull pat=1,pat2=1;
      ull busu = black-i;
      vector<int> si,bo;
      //rep(k,1,black+1){
      dow(k,black+1,1){
        si.push_back(k);
        //pat2*=k;
      }
      dow(k,busu+1,1){
        bo.push_back(k);
        //pat2/=k;
      }
      dow(k,i+1,1){
        bo.push_back(k);
        //pat2/=k;
      }
      //cout << pat << endl;
      rep(isi,0,si.size()){
        pat*=si[isi];
        rep(ibo,0,bo.size()){
          if(pat%bo[ibo] == 0){
            pat/=bo[ibo];
            bo.erase(bo.begin() + ibo);
          }
        }
      }
      cnt+=pat;
      //cnt2+=pat2;
    }
  }
  //cout << cnt << " " << cnt2 << endl;
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3160
#! /usr/bin/env python3
N = int(input())
A = [int(i) for i in input().split()]

def gcd(a, b):
    while b > 0:
        c = a % b
        a = b
        b = c
    return int(a)

def lcm(a, b):
    return a // gcd(a, b) * b

l = 1
for i in range(N):
    l = lcm(l, A[i])

ans = 0
MOD = int(1e9 + 7)
for a in A:
    ans += int(l // a)
    # ans %= MOD

print(ans % MOD)

Measured memory_bytes: 4084