akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

void solve(v2_int &a, int i, v_int &cnt) 
{
    for(auto b : a[i]) {
        if(cnt[b]) { 
            cnt[b] = 0;
            solve(a, b, cnt);
        }
    }
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    
    v2_int a(n);
    v_int cnt(n);

    irep(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        a[x-1].push_back(y-1);
        a[y-1].push_back(x-1);
        cnt[x-1]++; cnt[y-1]++;
    }
    
    int ans = 0;
    vector<pii> idx;
    irep(i, n) {
        if(cnt[i]) {
            idx.push_back(make_pair(cnt[i], i));
        } else {
            ans++;
        }
    }
    sort(idx.rbegin(), idx.rend());

    for(auto i : idx) {
        int num = i.se;
        if(cnt[num]) {
            cnt[num] = 0;
            solve(a, num, cnt);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/


Measured memory_bytes: 14660
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, k;
	cin >> n >> k;
	int t = (n - 1) * (n - 2) / 2 - k;
	if(t < 0){ cout << "-1\n"; }
	else{
		vector<pii> ans;
		for(int i = 2; i <= n; ++i){ ans.emplace_back(1, i); }
		for(int i = 2; i <= n && t > 0; ++i)
		for(int j = i + 1; j <= n && t > 0; ++j){
			ans.emplace_back(i, j);
			--t;
		}
		cout << ans.size() << '\n';
		for(cauto p : ans){
			cout << p.first << ' ' << p.second << '\n';
		}
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace abc108_c
{
    class program
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];
            long ans = 0;
            if (K%2==0)
            {
                K /= 2;
                for (long i = 1; i <= N / K; i++)
                {
                    double max = ((double)i+(double)N/(double)K)/2;
                    double min = ((double)i+1/(double)K)/2;
                    ans += ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1) * ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1);
                }
            }else
            {   
                for (long i = 1; i <= N / K; i++)
                {
                    double max = (double)i+(double)N/(double)K;
                    double min = (double)i+1/(double)K;
                    ans += ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1) * ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1);
                }
            }
            Console.WriteLine(ans);
        }
   }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  while(s[0]!='0'){
    int i,p=0;
    for(i=0;i<s.size();i++){
      p+=s[i]-'0';
    }
    cout << p << endl;
    cin >> s;
  }
}


Measured memory_bytes: 3132
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};


fn solve(n: u32) -> bool {
    let n = format!("{}", n);
    let n = n.as_bytes();
    n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3]
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", if solve(sc.next()) { "Yes" } else { "No" });
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(1024),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }
}


trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: fmt::Display, I: IntoIterator<Item = T>>(xs: I) {
    let stdout = io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    for x in xs.into_iter() {
        writeln!(stdout, "{}", x).unwrap();
    }
    stdout.flush().unwrap();
}


#[allow(dead_code)]
fn print_or<T: fmt::Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


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

int main()
{
    char a;
    cin >> a;
    if(a == 'A')cout << 'T';
    else if(a == 'G')cout << 'C';
    else if(a == 'T')cout << 'A';
    else if(a == 'C')cout << 'G';
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
matrix = []
hd = []
wd = []

for i in range(H):
    h = list(input())
    matrix.append(h)
    if h == ["."] * W:
        continue
    hd.append(i)

for i in range(W):
    w = [list(w_[i]) for w_ in matrix]
    if w == [["."]] * H:
        continue
    wd.append(i)

ansmatrix = []
row = []
for i in hd:
    for j in wd:
        row.append(matrix[i][j])
    ansmatrix.append(row)
    row = []

for ansrow in ansmatrix:
    print("".join(ansrow))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int64_t ans[100];
    ans[0] = 2;
    ans[1]=1;
   for(int i = 2;i < N+1;i++){
      ans[i] = ans[i - 1] + ans[i - 2];
    }
   cout << ans[N] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#define inf 1e9
using namespace std;

int main(void){
    int n;
    while (cin >> n && n) {
        vector<int> p(n+1, 0);
        vector<int> t(n+1, 0);
        for (int i = 1; i < n+1; i++) cin >> p[i] >> t[i];
        
        vector<vector<int> > dp(n+1, vector<int>(3, inf));
        dp[0][0] = 0;
        int cap = 0;
        
        for (int i = 1; i < n+1; i++) {
            for (int j = 0; j < 3; j++) {
                if (dp[i-1][j] == inf) continue;
                int pos = 0;
                if (j != 0) pos = p[i-1];
                int l = abs(p[i]-pos);
                int go = (j+1)*l;
                int back = (j+2)*p[i];
                
                if (t[i] < t[i-1]+go) continue;
                cap = i;
                if (j != 2) dp[i][j+1] = min(dp[i][j+1], dp[i-1][j]+l);
                
                if (i < n && t[i+1] < t[i]+back+p[i+1]) continue;
                dp[i][0] = min(dp[i][0], dp[i-1][j]+l+p[i]);
            }
        }
        if (cap < n) cout << "NG" << " " << cap+1 << endl;
        else cout << "OK" << " " << dp[n][0] << endl;
    }
}

Measured memory_bytes: 3000
/*
       _________
      /         \
     /  _     _  \
    /   0     0   \
   |       ||     |
   |              | => HI
    \     -----   /
     \           /
      \_ _ _ _ _/
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
const int maxN = 200100;
lli mem[maxN];
lli input[maxN];
const lli mod = 1e9 + 7;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
	for(int t = 1; t <= T; t++){
		int idx = 1;
		int n,k;
		cin >> n >> k;
		for(int i = 0;i < n; i++){
			cin >> input[i];
		}
		int l = 0,r = 0;
		lli res = 1;
		while(r < n){
			while(r - l < k and r < n){
				res += input[r++];
			}
			if(idx == 1){
				mem[idx++] = res;
				continue;
			}
			res -= input[l++];
			res += input[r++];
			mem[idx++] = res;
		}
		for(int i = 2;i < idx; i++){
			if(mem[i - 1] < mem[i]){
				cout << "Yes\n";
			}else{
				cout << "No\n";
			}
		}
	}
}





Measured memory_bytes: 6660
N, M, C = map(int, input().split())
B = input().split()
ans = 0
for i in range(N):
    A = input().split()
    tmp = 0
    for j in range(M):
        tmp += int(A[j]) * int(B[j])
    if tmp + C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 2940
n, l = map(int, input().split())
tastes = range(l, n + l)
ijo = [taste for taste in tastes if taste >= 0]
under = [taste for taste in tastes if taste < 0]
if len(ijo) == 0:
    print(sum(under[:-1]))
elif len(under) == 0:
    print(sum(ijo[1:]))
else:
    print(sum(tastes))


Measured memory_bytes: 3060
import heapq
lunlun = [i for i in range(1, 10)]
heapq.heapify(lunlun)
K = int(input())
ans = 0

while K > 0:
    ans = heapq.heappop(lunlun)
    K -= 1
    last_digit = int(str(ans)[-1])
    up, down = last_digit + 1, last_digit - 1
    heapq.heappush(lunlun, ans * 10 + last_digit)
    if up < 10:
        heapq.heappush(lunlun, ans * 10 + up)
    if down >= 0:
        heapq.heappush(lunlun, ans * 10 + down)

print(ans)

Measured memory_bytes: 12208
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

All = A[0]
for i in range(1,N):
  All = All^A[i]
#print(All)

ans = []
for i in A:
  t = i^All
  ans.append(t)
print(*ans)

#temp = ((26^5)^7)^22
#print(temp)

Measured memory_bytes: 31596
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string s;
    cin >> s;
    cout << (s[0]!='7'&&s[1]!='7'&&s[2]!='7'?"No":"Yes");
    return 0;
}

Measured memory_bytes: 3620
n,q = list(map(int, input().split()))
p = [0]*n
t = [0]*n

for i in range(n):
    p[i],t[i] = list(input().split())

i = 0
sum_t = 0
while 1:
    if i==len(t):
        break
    tmp_t = int(t[i])-q
    if tmp_t<=0:
        sum_t += int(t[i])
        print(p[i],sum_t)
    else:
        sum_t += q
        p.append(p[i])
        t.append(tmp_t)        
    i+=1


Measured memory_bytes: 15136
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define int long long

using namespace std;

class Solver {
};

signed main() {
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0)break;

		vector<char> status(n, '#');
		for (int i = 0; i < m; i++) {
			char who;
			cin >> who;
			if (who == 'A') {
				for (int i = 0; i < n; i++) {
					if (status[i] == '#') {
						status[i] = 'A';
						break;
					}
				}
			}
			if (who == 'B') {
				bool valid = false;
				for (int i = n - 1; i >= 0; i--) {
					if (status[i] != '#')continue;

					if ((i + 1 < n && status[i + 1] == 'A')
						|| (i - 1 >= 0 && status[i - 1] == 'A'))continue;

					status[i] = 'B';
					valid = true;
					break;
				}

				if (!valid) {
					for (int i = 0; i < n; i++) {
						if (status[i] == '#') {
							status[i] = 'B';
							break;
						}
					}
				}
			}
			if (who == 'C') {
				bool valid = false;
				for (int i = 0; i <n; i++) {
					if (status[i] == '#')continue;

					if (i + 1 < n && status[i + 1] == '#') {
						status[i + 1] = 'C';
						valid = true;
						break;
					}
					if (i - 1 >= 0 && status[i - 1] == '#') {
						status[i - 1] = 'C';
						valid = true;
						break;
					}
				}

				if (!valid) {
					status[n / 2] = 'C';
				}
			}
			if (who == 'D') {
				vector<int> left(n, 0);
				int last = -1;
				for (int i = 0; i < n; i++) {
					if (status[i] != '#') last = i;
					else {
						if (last >= 0) left[i] = i - last;
						else left[i] = 1e9;
					}
				}
				last = -1;
				vector<int> right(n, 0);
				for (int i = n - 1; i >= 0; i--) {
					if (status[i] != '#')last = i;
					else {
						if (last >= 0) right[i] = last - i;
						else right[i] = 1e9;
					}
				}
				int now = 0;
				int dist = -1;
				for (int i = 0; i < n; i++) {
					if (status[i] != '#')continue;

					if (min(left[i], right[i]) > dist) {
						now = i;
						dist = min(left[i], right[i]);
					}
				}
				status[now] = 'D';
			}
		}

		for (int i = 0; i < n; i++) {
			cout << status[i];
		}
		cout << endl;
	}
}


Measured memory_bytes: 2992
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  REP(h,H){
    REP(w,W)cout<<(w<A xor h<B);
    cout<<endl;
  }
  return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<char> ans;
    while(n > 0){
        int scr = n % 26;
        if (scr == 0) scr = 26;
        ans.push_back('a' - 1 + scr);
        if (scr == 26) n--;
        n /= 26;
    }
    int sz = ans.size();
    for (int i = sz - 1; i >= 0; i--){
        cout << ans[i];
    }
    cout << endl;
}

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

const int mod = 1e9+7;

int gcd(int a, int b) { // aとbの最大公約数（ユークリッドの互除法）
    if (b == 0) return a;
    return gcd(b, a % b);
}

int n; // 変数

int main() {
// input
    cin >> n;
// solve
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
// output
    cout << ans << "\n";
}

Measured memory_bytes: 3620
import sys
f = sys.stdin

def next_line(line):
    next_line = [0] * (len(line) - 1)
    for i in range(len(next_line)):
        next_line[i] = (line[i] + line[i + 1]) % 10
    return next_line

for line in f:
    line = list(map(int,line.strip()))
    while 1 < len(line):
        line = next_line(line)
    print(*line)

Measured memory_bytes: 6720
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T [MAX];
int n;

void preParse (int u) {
	if ( u == NIL ) return;
	printf ( " %d", u );
	preParse ( T[u].l );
	preParse ( T[u].r );
}

void inParse (int u ) {
	if ( u == NIL ) return;
	inParse ( T[u].l );
	printf ( " %d", u );
	inParse ( T[u].r );
}

void postParse (int u ) {
	if ( u == NIL ) return;
	postParse ( T[u].l );
	postParse ( T[u].r );
	printf ( " %d", u );
}

int main () {
	int i, v, l, r, root;
	
	scanf ( "%d", &n );
	for ( i = 0; i < n; i++ ) {
		T[i].p = NIL;
	}
	
	for ( i =  0; i < n; i++ ) {
		scanf ("%d %d %d", &v, &l, &r );
		T[v].l = l;
		T[v].r = r;
		if ( l != NIL ) T[l].p = v;
		if ( r != NIL ) T[r].p = v;
	}
	
	for ( i = 0; i < n; i++ ){
		if ( T[i].p == NIL ) root = i;
	}
	printf ( "Preorder\n" );
	preParse ( root );
	printf ( "\n" );
	printf ( "Inorder\n" );
	inParse ( root );
	printf ( "\n" );
	printf ( "Postorder\n" );
	postParse ( root );
	printf ( "\n" );
	
	return 0;
}


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

int main(void) {
    int H,W;cin>>H>>W;
    for (int i = 0; i <= H + 1; i++) {
        for (int j = 0; j <= W + 1; j++) {
            if (i == 0 || i == H + 1) cout << "#";
            else {
                if (j == 0 || j == W + 1) cout << "#";
                else {
                    char a;cin>>a;
                    printf("%c", a);
                }
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> A;
    int N; cin>>N;
    double a;
    double ans;a=ans=0.0;
    A.resize(N);

    for(int i=0;i<=N-1;i++){
        cin>>A[i];
    }
    for(int i=0;i<=N-1;i++) {
        a=1.0/A[i]+a;
    }

    ans=1.0/a;

    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template < typename T >
ostream &operator<<(ostream &os, const vector< vector< T > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
int main() {
	ll N, X;
	cin >> N >> X;
	vector< ll > A(N);
	rep(i, N) cin >> A[i];
	ll ans = LLONG_MAX / 2;
	vector< vector< ll > > dp(N, vector< ll >(N, LLONG_MAX / 2));
	rep(i, N) dp[i][0] = A[i];
	for (int j = 1; j < N; j++)
		rep(i, N) {
			dp[(i + 1) % N][j] = min(dp[(i + 1) % N][j - 1], dp[i][j - 1]);
			//dp[i][j] = min(dp[i][j - 1], A[((i - j) % N + N) % N]);
		}
	rep(k, N) {
		ll tmp = k * X;
		rep(i, N) tmp += dp[i][k];
		chmin(ans, tmp);
	}
	//cout << dp;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31744
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, r) = in.readLine().split("\\s+").map(_.toInt)

    out.println(
      if (n < 10) {
        r + 100 * (10 - n)
      } else {
        r
      }
    )
    out.flush()
  }
}


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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    string s; cin >> s;
    string t; cin >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), [](const char& c1, const char& c2){return c1>c2;});

// cout << s <<endl;
// cout << t <<endl;

    Yes(s < t);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string o,e;
    cin>>o>>e;
    rep(i,o.size()){
        cout<<o[i];
        if(i<e.size()) cout<<e[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3636
n= int(input())
if 1<=n<=1000:print(1000-n)
if 1001<=n<=2000:print(2000-n)
if 2001<=n<=3000:print(3000-n)
if 3001<=n<=4000:print(4000-n)
if 4001<=n<=5000:print(5000-n)
if 5001<=n<=6000:print(6000-n)
if 6001<=n<=7000:print(7000-n)
if 7001<=n<=8000:print(8000-n)
if 8001<=n<=9000:print(9000-n)
if 9001<=n<=10000:print(10000-n)

Measured memory_bytes: 9196
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> is;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	is.push_back(a);
	is.push_back(b);
	is.push_back(c);
	sort(is.begin(), is.end());
	int n = is[2];
	if ((is[0] + is[1]) % 2 == 1) {
		++n;
	}
	cout << (3 * n - a - b - c) / 2;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002

#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b; 
	while (cin >> a >> b) {
		string str = to_string(a + b);
		cout << str.length() << endl;
	}
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T>istream&operator>>(istream&s,vector<T>&v){for(int i=0;i<v.size();++i){s>>v[i];}return s;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x))
#define fr(i,n) for(int i=0;i<(n);++i)
#define foor(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,n) for(int i=(n);i--;)
#define roof(i,b,a) for(int i=(b);i>=(a);--i)
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef long long ll;
 
ll a[100000];
ll b[100000];
main(){
	int X,Y,Z;
	cin>>X>>Y>>Z;
	vector<pii>ab;
	ll s=0;
	fr(i,X+Y+Z){
		int a,b,c;
		cin>>a>>b>>c;
		s+=c;
		ab<<pii{a-c,b-c};
	}
	sort(all(ab),[](const pii&x,const pii&y){return(x.first-x.second)<(y.first-y.second);});
	{
		priority_queue<int>pq;
		fr(i,X+Y+Z){
			a[i]=(i?a[i-1]:0)+ab[i].second;
			pq.push(-ab[i].second);
			if(i>=Y){
				a[i]+=pq.top();
				pq.pop();
			}
		}
	}
	{
		priority_queue<int>pq;
		rf(i,X+Y+Z){
			b[i]=(i<X+Y+Z-1?b[i+1]:0)+ab[i].first;
			pq.push(-ab[i].first);
			if(i<Y+Z){
				b[i]+=pq.top();
				pq.pop();
			}
		}
	}
	ll t=-1e18;
	foor(i,Y,Y+Z){
		t=max(t,a[i-1]+b[i]);
	}
	cout<<s+t;
}


Measured memory_bytes: 3444
import java.util.*;

public class Main {
  public static void main(String[] args ) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if(A==B && B!=C){
      System.out.println("Yes");
    }else if(B==C && C!=A){
      System.out.println("Yes");
    }else if(C==A && A!=B){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];

int n,H,D[MAX];

int getDepth(int u)
{
  int d=0;
  while(T[u].p != NIL)
    {
      u = T[u].p;
      d++;
    }
  return d;
}


void print(int u)
{
  int i,c;

  printf("node %d:",u);
  printf(" ");
  printf("parent = %d,",T[u].p);
  printf(" ");
  printf("depth = %d,",D[u]);
  printf(" ");

  if(T[u].p == NIL)
    {
      printf("root,");
      printf(" ");
    }
  else if(T[u].l == NIL)
    {
      printf("leaf,");
      printf(" ");
    }
  else
    {
      printf("internal node,");
      printf(" ");
    }
  printf("[");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r)
    {
      if(i) printf(", ");
      printf("%d",c);
    }

  printf("]\n");
}



int main()
{
  int i,j,d,v,c,l;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].p = T[i].l = T[i].r =NIL;
    }

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&v,&d);
      for(j=0;j<d;j++)
	{
	  scanf("%d",&c);
	  if(j==0) T[v].l=c;
	  else T[l].r =c;
	  l=c;
	  T[c].p =v;
	}
    }

  H=0;
  for(i=0;i<n;i++)
    {
      D[i]=getDepth(i);
      if(D[i]>H)H=D[i];
    }

  for(i=0;i<n;i++) print(i);
  return 0;
}



Measured memory_bytes: 3260
#include <iostream>
using namespace std;
int main() {
	int n, m, a;
	cin >> n >> m;
	int x[n] = {0};
	for (int i = 0; i < 2 * m; i++) {
		cin >> a;
		x[a - 1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << x[i] << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
int a[2345][2345], n, x, ans, cnt;
signed main() {
	cin >> n >> x;
	for (int i = 1; i <= n; i++) {
		cin >> a[i][0];
		ans += a[i][0];
	}
	for (int j = 1; j <= n; j++) {
		cnt = x * j;
		for (int i = 1; i <= n; i++) {
			int p = i - j; if (p <= 0)p += n;
			a[i][j] = min(a[i][j - 1], a[p][0]);
			cnt += a[i][j];
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 37120
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll x, y;

bool solve() {
    return abs(x - y) > 1;
}

void input() {
    cin >> x >> y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"Alice":"Brown") << endl;
}


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

int main() {
    int n;
    cin>>n;
    int dp[n+1]{};
    dp[0]=1;
    for (int i=4;i<=n;i++)
        dp[i]|=dp[i-4];
    for (int i=7;i<=n;i++)
        dp[i]|=dp[i-7];
    if (dp[n])
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int x,y,temp,r;

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

  if(x < y){
    temp = x; 
    x = y;
    y = temp;
  }


  while((r = x%y) != 0){
    x = y;
    y = r;
  }

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

  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
int sum(int x){
int a=0;
while(x>0){
  a+= x%10;
  x=x/10;
}
return a;
}

int main(){
  int n,c,d,total=0,y;
  cin>>n>>c>>d;
  for(int i=1;i<n+1;i++){
    int total=sum(i);
    if(total>=c and total<=d){
      y+=i;
    }
  }
  cout<<y<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
typedef long long ll;
int main()
{
    ll i,j,ans,n;
    scanf("%lld",&n);
    if(n<=2)
    {
        printf("0\n");
    }
    else
    {
        if(n%2==0)
        {
            printf("%lld\n",(n-2)/2);
        }
        else
        {
            printf("%lld\n",n/2);
        }
    }
}


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

long long n,W,dp[105][100005],v[105],w[105],ans;

int main(){
    cin >> n >> W;
    for(int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0;i<=n;i++) dp[i][0]=W+1;
    for(int j=0;j<=100000;j++) dp[0][j]=W+1;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(long long j=0;j<=100000;j++){
            if(j>=v[i]) dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            else dp[i][j]=dp[i-1][j];
            if(dp[i][j]<=W) ans=max(ans,j);
        }
    }

    cout << ans;
}


Measured memory_bytes: 82556
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn practice_1() {
    input! {
    n: i32,
    m: [i32; 2],
    s: chars,
    }
    let s: Vec<char> = s;
    let s: String = s.into_iter().collect();

    println!("{} {}", n + m[0] + m[1], s);
}

#[allow(dead_code)]
fn abc086_a() {
    input! {
    n: [i32; 2],
    }
    let prod: i32 = n[0] * n[1];
    let res = if prod % 2 == 0 {
        "Even"
    } else {
        "Odd"
    };
    println!("{}", res)
}

#[allow(dead_code)]
fn abc081_a() {
    input! {
    s: chars,
    }
    let s: Vec<char> = s;
    let res: u32 = s.into_iter().map(|n| {
        n.to_digit(10).unwrap()
    }).sum();

    println!("{}", res)
}

#[allow(dead_code)]
fn abc081_b() {
    input! {
    n: i32,
    arr: [i32; n],
    }
    let mut arr: Vec<i32> = arr;
    let mut cnt = 0;

    loop {
        if arr.iter().any(|v| (v % 2) == 1) {
            break;
        }
        arr = arr.iter().map(|v| v / 2).collect();
        cnt += 1;
    }

    println!("{}", cnt)
}

#[allow(dead_code)]
fn abc087_b() {
    input! {
    n_500: i32,
    n_100: i32,
    n_50: i32,
    total: i32,
    }

    let n_500: i32 = n_500;
    let n_100: i32 = n_100;
    let n_50: i32 = n_50;
    let total: i32 = total;
    let mut cnt = 0;

    for i in 0..n_500 + 1 {
        for j in 0..n_100 + 1 {
            for k in 0..n_50 + 1 {
                let total_tried = i * 500 + j * 100 + k * 50;
                if total_tried == total {
//                    println!("{}, {}, {}", i, j, k);
                    cnt += 1;
                }
            }
        }
    }

    println!("{}", cnt)
}


fn main() {
    abc081_b()
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    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 pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    mint ans = 0;
    mint two = 2;
    vec<int> s(N,0);
    auto dfs = [&](auto& self,int cur,int par)->void{
        s[cur] = 1;
        vec<int> v;
        for(auto& e:g[cur]) if(e!=par){
            self(self,e,cur);
            v.push_back(s[e]);
            s[cur] += s[e];
        }
        mint c = two.pow(N-1)-1;
        if(g[cur].size()==1) return ;
        for(auto& x:v) c -= two.pow(x)-1;
        c -= two.pow(N-s[cur])-1;
        ans += c;
    };

    dfs(dfs,0,-1);
    cout << (ans*(two.pow(N)).inv()).x << endl;
}

Measured memory_bytes: 30080
#include <iostream>
#include <memory.h>

using namespace std;
const int maxn = 1000 + 5;

bool exist[maxn];
int X;

int quick_exp(int x, int y) {
	int ori = x, res = 1;
	while (y) {
		if (y & 1)
			res *= ori;
		ori *= ori;
		y >>= 1;
	}
	return res;
}

void work(int p) {
	int x = 1, res = 1;
	while (res < maxn) {
		exist[res] = true;
		x++;
		res = quick_exp(x, p);
	}
}

void init()
{
	for (int i = 2; i <= 10; i++) {
		work(i);
	}
}

int main()
{
	
	cin >> X;
	memset(exist, false, sizeof(exist));
	init();
	int res = -1;
	for (int i = X; i >= 0; i--) {
		if (exist[i]) {
			res = i;
			break;
		}
	}
	cout << res << endl;
	return 0;
}

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

const int mod = 1e9 + 7;

long long fast_power(long long base, long long exp) {
    long long ans = 1;
    base %= mod;
    while (exp > 0) {
        if (exp & 1) ans = (ans * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return ans;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	long long fact1 = 1;
	for(int i = 1; i <= a; ++i)
		fact1 *= i, fact1 %= mod;
	long long fact2 = 1;
	for(int i = 1; i <= b; ++i)
		fact2 *= i, fact2 %= mod;
	long long tot = fast_power(2, n) - 1;
	long long cur1 = 1, cur2 = 1;
	for(int i = n; i >= n - a + 1; --i) 
		cur1 *= i, cur1 %= mod;
	for(int i = n; i >= n - b + 1; --i)
		cur2 *= i, cur2 %= mod;
	cur2 = cur2 * fast_power(fact2, mod - 2) % mod;
	cur1 = cur1 * fast_power(fact1, mod - 2) % mod;
	tot = (tot - cur2 - cur1) % mod;
	tot = (tot + mod) % mod;
	cout << tot;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void) {
    double a, b, c;
    double C;
    double S, L, h;
    double pi = acos(-1);
    
    cin >> a >> b >> C;
    C = pi * C / 180;
    S= a * b * sin(C) / 2;
    c = sqrt(a*a + b*b - 2*a*b*cos(C));
    L = a + b + c;
    h = S * 2 / a;
    
    printf("%lf\n", S);
    printf("%lf\n", L);
    printf("%lf\n", h);
    
    return 0;
}




Measured memory_bytes: 3572
#include <stdio.h>
#define MAX 100000

int F[MAX];

int fibonacci(int n){
  int i;

  F[0] = 1;
  F[1] = 1;
  
  for(i=2;i<=n;i++){
    F[i]=F[i-2]+F[i-1];
  }

  return F[n];
}

int main(){
  
  int n;

  scanf("%d",&n);
  
  printf("%d\n",fibonacci(n));
  
  return 0;
}

Measured memory_bytes: 596
n = int(input())
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	elif i % 2 == 1:
		bo.append(max(a))
		a.remove(max(a))
print(sum(al)-sum(bo))


Measured memory_bytes: 3060
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
 
h = sorted(h)
 
ans = h[k-1] - h[0]
for i in range(1, n-k+1):
    ans = min(ans, h[i+k-1] - h[i])

print(ans)

Measured memory_bytes: 8280
#include<iostream>
using namespace std;
int g[100][100],a[10000];
int main(){
	int h,w,n;
	while (cin>>h>>w){
		cin>>n;
		for (int i=0;i<n;i++)cin>>a[i];
		int count=0,co=1;
		for (int i=0;i<h;i++){
			if (i%2==0){
				for (int j=0;j<w;j++){
					g[i][j]=co;
					count++;
					if (count==a[co-1]){
						count=0;
						co++;
					}
				}
			}else{
				for (int j=w-1;j>=0;j--){
					g[i][j]=co;
					count++;
					if (count==a[co-1]){
						count=0;
						co++;
					}
				}
			}
			
		}
		for (int i=0;i<h;i++){
			for (int j=0;j<w;j++)cout<<g[i][j]<<' ';
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  string A,B,C;
  cin >> A >> B >> C;
  cout << ((A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) ? "YES" : "NO") << endl; 
  return 0;
}





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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c;
	if (a >= b && a >= c) {
		cout << b + c;
	}
	else if (b >= a && b >= c) {
		cout << a + c;
	}
	else {
		cout << a + b;
	}

}

Measured memory_bytes: 384
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_C&lang=jp
  * Math Functions - Standard Deviation
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.toInt).takeWhile(_ != 0)
      .map {
        n => {
          val scores = io.StdIn.readLine().split(" ").map(_.toDouble)
          val mean = scores.sum / n
          math.sqrt(scores.foldLeft(0.0)((acc, x) => acc + x * x) / n - (mean * mean))
        }
      }
      .foreach(println)
  }
}

Measured memory_bytes: 45052
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
 /*   double t,x;
    cin>>t>>x;
    t=t/x;
    cout<<t*1.0<<'\n';*/
  
   /* int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<'\n';*/

   /* int d;
    cin>>d;
    if(d==22){
        cout<<"Christmas Eve Eve Eve"<<'\n';
    }else if(d==23){
        cout<<"Christmas Eve Eve"<<'\n';
    }else if(d==24){
        cout<<"Christmas Eve"<<'\n';
    }else if(d==25){
        cout<<"Christmas"<<'\n';
    }*/

   /* int x,y;
    cin>>x>>y;
    y=y/2;
    cout<<x+y<<'\n';*/

   /* int n,a,b;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<'\n';
    }else{
        cin>>a>>b;
        cout<<a+b<<'\n';
    }*/

    int n;
    cin>>n;
    if(n==111){
        cout<<999<<'\n';
    }else if(n==119){
        cout<<991<<'\n';
    }else if(n==199){
        cout<<911<<'\n';
    }else if(n==191){
        cout<<919<<'\n';
    }else if(n==999){
        cout<<111<<'\n';
    }else if(n==911){
        cout<<199<<'\n';
    }else if(n==919){
        cout<<191<<'\n';
    }else if(n==991){
        cout<<119<<'\n';
    }
}

Measured memory_bytes: 256
#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>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#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>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
struct ToUpper {
    char operator()(char c) { return toupper(c); }
};
struct ToLower {
    char operator()(char c) { return tolower(c); }
};
const int N=200010;
const int P=1000000007;
using ll = long long;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/

/*
	char s[N];
	strlen(s)
*/

/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

/*添字1がa個、2がb個
  vector<vector<ll>> map(a,vector<ll>(b));
*/

int main(){
	ll a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if( a  ==0){
    cout<<1<<endl;
  }if(  b ==0){
    cout<<2<<endl;
  }if(c==0){
    cout<<3<<endl;
  }if( d  ==0){
    cout<<4<<endl;
  }if( e  ==0){
    cout<<5<<endl;
  }


}



Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
	char a[10]={0},b[10]={0},c[10]={0};
	int x,y;
	scanf("%s %s",a,b);
	scanf("%d %d\n",&x,&y);
	scanf("%s",c);
	if(c[0]==a[0])
		x--;
	else 
		y--;
	printf("%d %d",x,y);
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
    int k = 0;
    std::cin >> k;

    int a = 0;
    std::cin >> a;
    int b = 0;
    std::cin >> b;

    for (auto dist = a; dist <= b; ++dist)
    {
        if ((dist % k) == 0)
        {
            std::cout << "OK";
            return 0;
        }
    }
    std::cout << "NG";
}

Measured memory_bytes: 3596
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)


int main(){
    int n,k;
    cin >> n >> k;
    long long costs[n][2];
    rep(i,0,n){
        cin >> costs[i][0];
    }
    costs[0][1] = 0;
    costs[1][1] = abs(costs[0][0] - costs[1][0]);
    rep(i,2,n){
        long long minCost = -1;
        rep(j,1,k+1){
            if(i < j)break;//それ以上戻れないとき
            long long a = costs[i-j][1] + abs(costs[i][0] - costs[i-j][0]);
            if(minCost == -1){
                minCost = a;
            }else{
                minCost = min(a,minCost);
            }
        }
        costs[i][1] = minCost;
    }
    cout << costs[n-1][1] << endl;
    //--------------
    return 0;
}

Measured memory_bytes: 1792