akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	std::string buf;

	for(;;){
		int sum = 0;
#if INPUT_FROM_FILE
		std::getline(ifs, buf);
#else
		std::getline(std::cin, buf);
#endif
		if(buf.at(0) == '0'){ break;}

		for(int i = 0; i < buf.size(); i++){
			sum += buf.at(i) - '0';
		}
		std::cout << sum << std::endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main()
{   
    int a, b;
    cin >> a >> b;
    
    /* 面積はa×bで，周長はa, bが2辺ずつ*/

    cout << a * b << " " << 2 * (a + b) << endl;
}


Measured memory_bytes: 3016
#include <iostream>
using namespace std;
int main() {
  int d;
  cin >> d;
  if (d==25) cout << "Christmas" << endl;
  else if (d==24) cout << "Christmas Eve" << endl;
  else if (d==23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var X = Sarray()[0];
            for (var i = 0; ; ++i)
                if (2 * X <= i * (i + 1))
                {
                    WriteLine(i);
                    return;
                }
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	multiset<int, greater<int>> st, cur;
	for(int i=0; i<(1<<n); i++) {
		int t;
		cin >> t;
		st.insert(t);
	}
	cur.insert(*st.begin());
	st.erase(st.begin());
	while(st.size()) {
		vector<int> v;
		for(int c: cur) {
			auto it = st.upper_bound(c);
			if(it == st.end())
				return !(cout << "No");
			v.push_back(*it);
			st.erase(it);
		}
		cur.insert(v.begin(), v.end());
	}
	cout << "Yes";
}

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

int main()
{
    char s[20];
    while(cin >> s)
    {
        int len = strlen(s);
        for(int i = 0;i < len;i++)
        {
            if(s[i] != ',')
            cout << s[i];
            else
            cout << " ";
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  // O(1)のアルゴリズム
  for (int i = 1; i <= 9; i++)
  {
    for (int j = i; j <= 9; j++)
    {
      if (i * j == N)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

def main():
    x,y,a,b,c=map(int,input().split())
    p=sorted([int(i) for i in input().split()],reverse=1)[:x]
    q=sorted([int(i) for i in input().split()],reverse=1)[:y]
    r=[int(i) for i in input().split()]
    print(sum(sorted(p+q+r,reverse=1)[:x+y]))

if __name__=="__main__":
    main()

Measured memory_bytes: 22432
#include <stdio.h>

int main( int argc , char *argv[] )
{
	int x[50];
	int y[50];
	int n;
	int i,j;
	int max = 0;

	int dx[50*50];
	int dy[50*50];

	int f[50*50];

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

	for( i = 0 ; i < n ; i++ ) {
		scanf( "%d %d\n" , &(x[i]) , &(y[i]) );
	}

	for( i = 0 ; i < n ; i++ ) {
		for( j = 0 ; j < n ; j++ ) {
			if( i == j ) continue;

			dx[i*50+j] = x[i] - x[j];
			dy[i*50+j] = y[i] - y[j];
		}
	}

	for( i = 0 ; i < 50*50 ; i++ ) {
		f[i] = 0;
	}

	for( i = 0 ; i < n ; i++ ) {
		for( j = 0 ; j < n ; j++ ) {
			int k,l;
			int cnt = 0;
			int p,q;

			if( i == j ) continue;

			if( f[i*50+j] == 1 ) continue;

			f[i*50+j] = 1;

			p = dx[i*50+j];
			q = dy[i*50+j];

			for( k = 0 ; k < n ; k++ ) {
				for( l = 0 ; l < n ; l++ ) {
					if( k == l ) continue;

					if( ( p == dx[k*50+l] ) && ( q == dy[k*50+l] ) ) {
						f[k*50+l] = 1;
						cnt++;
					}
				}
			}

			if( max < cnt ) {
				max = cnt;
			}
		}
	}

	printf( "%d\n" , n - max );

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
	long n, a, b;
	cin >> n >> a >> b;
	if(a > b) cout << 0 << endl;
	else if(a < b && n == 1) cout << 0 << endl;
	else cout << (n - 2) * (b - a) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
require 'set'

def main
    n,m = gets.chomp.split(" ").map(&:to_i)
    to = Array.new(n+1).map{Array.new()}
    m.times do
        a,b = gets.chomp.split(" ").map(&:to_i)
        to[a].push b
        to[b].push a
    end

    q = Queue.new
    ds = Array.new(n+1, -1)
    pre = Array.new(n+1, -1)

    q.push 1
    d = 0
    until q.empty?
        d += 1
        v = q.pop
        to[v].each do |w|
            next if ds[w] != -1
            q.push w
            ds[w] = d
            pre[w] = v
        end
    end
    puts 'Yes'
    puts pre[2..-1]
end

main

## イディオムなど
# until s.empty? do
#
## 配列のインデックス
# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
#
## 全探索
# [0, 1].repeated_permutation(n) do |combination| # 2^n の全探索
# array.combination(i) do |selected| # array から要素が i 個である部分列を全部抽出

Measured memory_bytes: 34524
import java.io.IOException;
import java.io.InputStream;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		MyComparator comp = new MyComparator();
		PriorityQueue<Long> pq = new PriorityQueue<Long>(comp);
		for (int i = 0; i < N; i++) {
			pq.add(sc.nextLong());
		}
		for (int i = 0; i < M; i++) {
			long val = pq.poll();
			if (val <= 0) {
				pq.add(val);
				break;
			}
			val /= 2;
			pq.add(val);
		}
		long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += pq.poll();
		}
		System.out.println(sum);

	}

}

class MyComparator implements Comparator {
	@Override
	public int compare(Object arg0, Object arg1) {
		long x = (long) arg0;
		long y = (long) arg1;

		if (x < y) {
			return 1;
		} else if (x > y) {
			return -1;
		} else {
			return 0;
		}
	}
}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 29172
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:u32=read();
    let b:u32=read();
    let c:u32=read();
    let x:u32=read();
    let mut ans = 0;
    for i in 0..a +1 {
      for j in 0..b +1 {
        for k in 0..c +1 {
          if i * 500 + j * 100 + k * 50 == x {
            ans += 1;
          }
        }
      }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

#define MAXCOUNT 1000000
#define MAXINTERVAL 100

//一定の間隔の要素を並び替える
int insertion_sort(int array[MAXCOUNT], int size, int interval);

int main(void)
{
	//sizeは入力されるデータの個数、order_countはソートで計算した回数、interval_countはinsertion_sortを呼び出す回数
	int i, size, order_count, interval_count;
	//intervalは並び替える要素の間隔を格納
	int interval[MAXINTERVAL];
	static int array[MAXCOUNT];

	scanf("%d", &size);

	interval_count = 0;
	//最終的に間隔は1となる
	interval[0] = 1;
	//データの入力と間隔を設定
	for(i = 0; i < size; i++){
		scanf("%d", &array[i]);

		if(((3 * interval[interval_count] + 1) <= size)){
			interval[interval_count + 1] = 3 * interval[interval_count] + 1;
			interval_count++;
		}
	}

	//挿入ソートを呼び出し要素を並び替える
	order_count = 0;
	for(i = interval_count; i >= 0; i--){
		order_count += insertion_sort(array, size, interval[i]);
	}

	//挿入ソートを呼び出した回数を表示
	printf("%d\n", interval_count + 1);
	//並び替えた要素の間隔を表示
	for(i = interval_count; i > 0; i--){
		printf("%d ", interval[i]);
	}
	printf("%d\n", interval[i]);

	//計算した回数を表示
	printf("%d\n", order_count);

	//並び替えた結果を表示
	for(i = 0; i < size; i++){
		printf("%d\n", array[i]);
	}

	return 0;
}

int insertion_sort(int array[MAXCOUNT], int size, int interval)
{
	//i、jは繰り返し変数、countは計算回数を、tempは挿入するデータを格納
	int i, j, count, temp;

	count = 0;
	for(i = interval; i < size; i++){
		//コピーを取る
		temp = array[i];
		j = i - interval;
		while(j >= 0 && array[j] > temp){
			//データをずらす
			array[j + interval] = array[j];
			j -= interval;
			count++;
		}
		array[j + interval] = temp;
	}

	return count;
}


Measured memory_bytes: 5640
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn dfs(tree: &Vec<Vec<usize>>, counter: &mut Vec<i64>, now: usize, from: usize) {
    for leaf in &tree[now] {
        if *leaf == from || *leaf == 1<<50 {
            continue;
        }
        counter[*leaf] += counter[now];
        dfs(tree, counter, *leaf, now);
    }
}
fn main() {
    input!{
        n: usize,
        q: usize,
        ab: [(usize1, usize1);n-1],
        px: [(usize1, i64); q],
    }
    // println!("{:?}", ab);
    // println!("{:?}", px);
    let mut counter = vec![0;n];
    for &(p, x) in &px {
        counter[p] += x;
    }
    let mut tree = vec![vec![];n];
    for &(a,b) in &ab {
        tree[a].push(b);
    }
    // println!("{:?}", tree);
    dfs(&tree, &mut counter, 0, 1<<50);
    // println!("{:?}", counter);
    for i in 0..n {
        if i==n-1 {
            println!("{}", counter[i]);
        }else{
            print!("{} ", counter[i]);
        }

    }
}

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

int main(){
  int N;
  cin >> N;
 
  if(N %10== 2 || N %10==4 || N%10==5 || N %10==7 || N%10==9){
    cout << "hon" << endl;
  }
  else if(N%10 ==0 || N%10==1 || N%10 ==6 || N%10 ==8){
    cout << "pon" << endl;
  }
  else{
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3636
s=input()
list=[0 for _ in range(len(s) + 1)]

for n in range(0, len(s), 1):
    if '<' == s[n] and list[n] >= list[n + 1]:
        list[n + 1] += list[n] - list[n + 1] + 1

for n in range(len(s) - 1, -1, -1):
    if '>' == s[n] and list[n] <= list[n + 1]:
        list[n] += list[n + 1] - list[n] + 1

print(sum(list))


Measured memory_bytes: 23988
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rep(i,j) for(ll i=0;i<j;i++)
#define repf(i,m,j) for(ll i=m;i<j;i++)
#define pb push_back
#define sort(a) sort(all(a))
int main()
{
	vector<int> a(100);
	vector<int> b(100);
	int N;
	int num;
	cin>>N;
	rep(i,N)scanf("%d",&b[i]);
	rep(i,N){
		if(i+1>=b[i]) a.insert(a.begin()+b[i]-1,b[i]);
		else{
			printf("%d\n",-1); return EXIT_SUCCESS;	
		}
	}
	rep(i,N) printf("%d\n",a[i]);
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int suma[100010] = {};
	for (int i = 1; i <= n; i++) {
		suma[i] = suma[i - 1] + a[i - 1];
	}
	int ans = -MOD;
	int idx = -1;
	for (int i = 1; i < n; i++) {
		int tmp = suma[n] - suma[i] - suma[i];
		if (tmp > ans) {
			ans = tmp;
			idx = i;
		}
	}
	cout << ans << endl;
	int now = a[idx - 1];
	for (int i = idx; i < n - 1; i++) {
		cout << now << " " << a[i] << endl;
		now -= a[i];
	}
	cout << a[n - 1] << " " << now << endl;
	now = a[n - 1] - now;
	for (int i = 0; i < idx - 1; i++) {
		cout << now << " " << a[i] << endl;
		now -= a[i];
	}
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  string s;
  ll k;
  cin >> s >> k;
  ll count1 = 0;
  char c;
  for(i = 0; i < s.size() && s[i] == '1'; i++)
    count1++;
  c = s[i];
  //cout << count1 spa c spa endl;
  if(k <= count1)
    cout << '1' << endl;
  else
    cout << c << endl;
    
 
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
INF = 10**8
dp = [INF]*n
dp[0] = 0
for i in range(n-1):
    if i == 0:
        dp[i+1] = abs(h[i+1]-h[i])
    else:
        dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]), dp[i-1]+abs(h[i+1]-h[i-1]))
print(dp[n-1])


Measured memory_bytes: 13924
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;

int insertion_sort(int A[], int N , int g) {
    int count = 0;
	for (int i = g; i < N; ++i) {
		int v = A[i];
        int j = i - g;
		for (; j >= 0 && A[j] > v; j -= g) {
			A[j + g] = A[j];
            ++count;
		}
        A[j + g] = v;
	}
    return count;
}

int shell_sort(int A[], int N, vector<int> G){
    int count = 0;
    for(auto g = G.end() - 1, begin = G.begin(); g >= begin; --g){
        count += insertion_sort(A, N, *g);
    }
    return count;

}

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

	int A[1000000] = {};
	int N;
	cin >> N;
    vector<int> G;
    G.reserve(N);

    for(int h = 1;; h = 3*h+1){
        if(h > N){
            break;
        }else{
            G.emplace_back(h);
        }
    }
    cout << G.size() << "\n";
    for(int end = G.size() - 1, i = end; i >= 0; --i){
        if(i != end) cout << " ";
        cout << G[i];
    }
    cout << "\n";

	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
    int count = shell_sort(A, N, G);
    cout << count << "\n";
	for (int i = 0; i < N; ++i) {
		cout << A[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 7124
#include <iostream>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;
    int x=0;
    int max=0;
    for (int i = 0; i < N; ++i) {
        if (S[i]=='I'){
            ++x;
        }else if(S[i]=='D'){
            --x;
        }
        if (x>max){
            max=x;
        }
    }
    cout << max;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

double pi=3.1415926535897932384626433;
double A,B,H,M;

int main(){
    cin>>A>>B>>H>>M;

    double h=pi/6*H+(pi/6)/60*M;
    double m=M/60*2*pi;
    double a=cos(h-m);

    double ans=A*A+B*B-2*A*B*a;
    ans=sqrt(ans);

    cout<<setprecision(20)<<ans<<endl;
}

Measured memory_bytes: 4228
N=int(input())
D, X=map(int,input().split())
A=[]
for i in range(N):
    A.append(int(input()))

ans=0
for i in range(N):
    if A[i]<=D:
        ans+=(D-1)//A[i]+1
    else:
        ans+=1
print(ans+X)


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    ArrayList<Integer> array = new ArrayList<Integer>();
    for(int a=0;a<n;a++){
      array.add(sc.nextInt());
    }
    int count = 0;
    for(int b=0;b<n;b++){
      if(array.get(b)<k-array.get(b)){
        count += array.get(b)*2;
      }else{
        count += (k-array.get(b))*2;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
n = int(input())
L = [[0,0],[100,0]]
for i in range(n):
    sub = []
    for j in range(len(L)-1):
        K = []
        a = L[j][0]
        b = L[j][1]
        c = L[j+1][0]
        d = L[j+1][1]
        if a == 0:
            K.append([a,b])
        K.append([a+((c-a)/3),b+((d-b)/3)])
        K.append([(a+c)/2+(b-d)*(3**0.5)/6,(b+d)/2+(c-a)*(3**0.5)/6])
        K.append([a+((c-a)*2/3),b+((d-b)*2/3)])
        K.append([c,d])
        sub = sub+K
    L = sub
for i in range(len(L)):
    print(L[i][0],L[i][1])


Measured memory_bytes: 6160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll h,w;
    cin >> h >> w;
    if(h == 1 || w == 1)pf(1);
    else pf((h * w + 1) / 2);
    return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e3 + 5;
const ll llinf = 1e18;

int N, a[maxn];
int K, Q;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> K >> Q;
  int res = 1e9;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  for(int pv = 1; pv <= N; ++pv){
    vector<int> all;
    for(int i = 1; i <= N; ++i){
      if(a[i] < a[pv]) continue;
      int j = i;
      vector<int> v;
      while(j <= N && a[j] >= a[pv]){
        v.pb(a[j]);
        ++j;
      }
      i = j - 1;
      sort(v.rbegin(), v.rend());
      for(int k = K - 1; k < v.size(); ++k)
        all.pb(v[k]);
    }
    sort(all.begin(), all.end());
    if(all.size() >= Q) res = min(res, all[Q - 1] - a[pv]);
    //if(a[pv] == 1) for(auto & it : all) cerr << it << ' ';
  }
  cout << res;
}


Measured memory_bytes: 256
def out (a) 
    3.times do |b|
        10.times do |f|
            print " ", a[b][f]
        end
        print "\n"
    end
end

a0 = Array.new(3).map{Array.new(10,0)}
a1 = Array.new(3).map{Array.new(10,0)}
a2 = Array.new(3).map{Array.new(10,0)}
a3 = Array.new(3).map{Array.new(10,0)}
n = gets.to_i
n.times do
    i = gets
    b = i.split[0].to_i - 1
    f = i.split[1].to_i - 1
    r = i.split[2].to_i - 1
    v = i.split[3].to_i
    a0[f][r] += v if b == 0
    a1[f][r] += v if b == 1
    a2[f][r] += v if b == 2
    a3[f][r] += v if b == 3
end
out(a0)
print "####################\n"
out(a1)
print "####################\n"
out(a2)
print "####################\n"
out(a3)


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

typedef long long ll;

#define lp(i,n) for(ll i=0;i<ll(n);i++)
#define lp3(i,s,n) for(ll i=s;i<ll(n);i++)
#define lpd3(i,s,n) for(ll i=s;i>=ll(n);i--)
#define all(c) (c).begin(),(c).end()
#define sz(c) ((c).size())
#define pb push_back
#define endl '\n'
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;

int n, W;
vector<int> v;
vector<int> w;
vector<vector<int> >dp;

int solve(int indx, int weight){

    if(weight > W)
        return -1e5;
    
    if(indx == n)
        return 0;

    if(dp[indx][weight] != -1)
        return dp[indx][weight];

    int ans1 = solve(indx+1, weight+w[indx]);
    int ans2 = solve(indx+1, weight);

    if(ans1 == -1e5 && ans2 == -1e5)
        return dp[indx][weight] = -1e5;

    return dp[indx][weight] = max(ans1+v[indx], ans2);

}

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

    cin>>n>>W;

    v.resize(n);
    w.resize(n);
    dp.assign(n,vector<int>(W+1,-1));

    lp(i, n)
        cin>>v[i]>>w[i];

    int ans = solve(0,0);
    cout<<(ans == -1e5?0:ans)<<endl;
    

    return 0;
}



Measured memory_bytes: 6812
import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    if len(nums)==1:
        return nums[0]
    return functools.reduce(euclid, nums)



n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(k)
a.sort()

sa=[]

for i in range(1,n+1):
    sa.append(a[i]-a[i-1])



print(gcd(sa))



Measured memory_bytes: 20588
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//ifstream cin("/home/mihai/Documents/c++/A/A.in");
//ofstream cout("/home/mihai/Documents/c++/A/A.out");

//ifstream f("perle.in");
//ofstream g("perle.out");

const int MAX = 1e9 + 5;

int main()
{
	int n;
	cin >> n;
	int mx = 0;
	int mi = MAX;
	while(n--)
	{
		int x;
		cin >> x;
		mi = min(mi, x);
		mx = max(mx, x);
	}
	cout << mx - mi;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n / 2 << endl;
  } else {
    cout << n / 2 + 1<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val Array(n,a)=input.split("\n").map(_.toInt)
    (n*n-a).toString
  }
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> road(N+1,0);
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b ;
    road.at(a)++;
    road.at(b)++;
  }
  for(int i=1;i<N+1;i++){
    cout << road.at(i) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int ans=100000;
    for (int i=1;n-i>0;i++) {
        int sum=0;
        string tmp1=to_string(i);
        string tmp2=to_string(n-i);
        for (int j=0;j<tmp1.size();j++) {
            sum+=tmp1[j]-48;
        }
        for (int k=0;k<tmp2.size();k++) {
            sum+=tmp2[k]-48;
        }
        if (sum<ans) {
            ans=sum;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}


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

int main(){
	int n;cin>>n;
	map<int,int> odd,even;
	rep(i,n){
		int a;cin>>a;
		if(i%2==0) even[a]++;
		else odd[a]++;
	}
	int mxo=0,mxe=0,mxo2=0,mxe2=0,mxo_number,mxe_number;
	for(auto i:odd) {
		if(mxo<i.second){
			mxo2=mxo;
			mxo=i.second;
			mxo_number=i.first;
		}
		else mxo2=max(mxo2,i.second);
	}
	for(auto i:even) {
		if(mxe<i.second){
			mxe2=mxe;
			mxe=i.second;
			mxe_number=i.first;
		}
		else mxe2=max(mxe2,i.second);
	}
	//cout<<mxo<<" "<<mxo2<<":"<<mxe<<" "<<mxe2<<"\n";
	if(mxo_number==mxe_number) cout<<min(n-mxe2-mxo,n-mxe-mxo2)<<"\n";
	else cout<<n-mxo-mxe<<"\n";
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;

string a, b;

int main()
{
	cin>>a>>b;
	if(a.size()  > b.size()) {cout<<"GREATER"<<endl; return 0;}
	else if(a.size() < b.size()) {cout<<"LESS"<<endl; return 0;}
	else
	{
		for(int i = 0; i < a.size(); i++)
		{
			if(a[i] > b[i]) {cout<<"GREATER"<<endl; return 0; }
			else if(a[i] < b[i]) {cout<<"LESS"<<endl; return 0; }
		}
		cout<<"EQUAL"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e4 + 5;
int n, k;
int box[MaxN];
int ans;
bool cmp(int x, int y){
	return x > y;
}
int main(){
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &box[i]);
	}
	sort(box + 1, box + 1 + n, cmp);
	ans = 0;
	for(int i = 1; i <= n; i++){
		int sum = 0;
		for(int j = i; j <= n; j++){
			sum += box[j];
			if(sum >= k){
				ans = max(ans, j);
				sum -= box[j];
			}
		}
	}
	printf("%d\n",n - ans);
}


Measured memory_bytes: 128
a = int(input())

name_list = []
time_list = []

for i in range(a):
  music = input().split()
  name_list.append(music[0])
  time_list.append(int(music[1]))
  
b = input()
c = name_list.index(b)
d = len(time_list)

e = sum(time_list[c+1:d])
print(e)
  

Measured memory_bytes: 3060
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a << x  if x >= (a=b)[-1]
    return a.unshift x  if x <= a[0]
    i = a.bsearch_index {|y| x <= (y.frozen? ? y: y[0])}
    b = a[i-=1]  if (b=a[i]).frozen? ? x<b: x<b[0]
  end  if b && b=a
  return a.insert(i+1, x)  unless a[i+9]
  i > 9 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a); r=a.shift; a.unshift *a.shift if !a[0].frozen?; r end
def poq(a); r=a.pop; b=a[-1]; a.push *(b[9]? poq(b): a.pop) if !b.frozen?; r end
N,M,*A = $<.read.split.map{|x| x.to_i}
A.sort!
M.times { break if A[-1]==0; enq A, (poq A)/2 }
p A.flatten.inject(0,:+)

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "No";
    else cout << "Yes";
    return 0;
}

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

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,a,b;

int main() {
	cin>>n>>m>>a>>b;
	for(int i=1;i<=2*b;i++,cout<<endl)
		if(i&1) {
			for(int j=1;j<=a;j++) cout<<0;
			for(int j=a+1;j<=m;j++) cout<<1;
		}
		else {
			for(int j=1;j<=a;j++) cout<<1;
			for(int j=a+1;j<=m;j++) cout<<0;
		}
	for(int i=2*b+1;i<=n;i++,cout<<endl) {
		for(int j=1;j<=a;j++) cout<<0;
		for(int j=a+1;j<=m;j++) cout<<1;
	}
	return 0;
}


Measured memory_bytes: 1280
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n,m;
cin>>n>>m;
vector<ll>v;
ll sum=0;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
    sum+=a;
}
double x=sum/(4.0*m);
ll cnt=0;
for(ll i=0;i<n;i++)
{
    double y=v[i]*1.0;
    if(y>=x)
    {
        cnt++;
    }
}
if(cnt>=m)
{
    cout<<"Yes"<<endl;
}else
{
    cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int cnt=0;
		for(int i=100;i>=1;i=i/10) {
			if(a/i!=0)	cnt++;
			a=a%i;
		}
		System.out.println(cnt);

	}

}

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

bool dislike[10];

int isCorrect(int n) {
	int temp = n;
	while (temp) {
		int rem = temp % 10;
		if (dislike[rem]) {
			return false;
		}
		temp /= 10;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		int digit;
		cin >> digit;
		dislike[digit] = true;
	}

	for (int i = n; ; ++i) {
		if (isCorrect(i)) {
			cout << i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n;
long long a[100005]={0},b[100005]={0}; 
int main(){
	scanf("%d",&n);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		a[i]=a[i-1]+x; 
	} 
	long long ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		b[i]=b[i-1]+x;
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,a[i]+(b[n]-b[i-1]));
	}
	cout<<ans;
    return 0;
}


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

void solve() {
    int a[5];
    for (int i = 0; i < 5; i++) {
        scanf("%d", a+i);
        if (a[i] == 0) {
            printf("%d\n", i+1);
        }
    }
}

int main(){
    solve();

	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/20  Problem: ABC 052 A / Link: http://abc052.contest.atcoder.jp/tasks/abc052_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s; cin >> s;
	FOR(i, 0, SZ(s)) {
		if (s[i] != ',')cout << s[i];
		else cout << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect
n, m = (int(i) for i in input().split())
yl = []
[yl.append([]) for _ in range(n)]
dl = []

for _ in range(m):
    p, y = (int(i) for i in input().split())
    yl[p-1].append(y)
    dl.append((p, y))

[yl[i].sort() for i in range(n)]

for p, y in dl:
    print("{:0>6}{:0>6}".format(p, bisect.bisect_left(yl[p-1], y)+1))

Measured memory_bytes: 30580
from collections import deque

N, K = map(int, input().split())
ps = list(map(int, input().split()))

Q = deque([(p + 1) / 2 for p in ps[:K]])

max_ = sum(Q)
now = max_
for p in ps[K:]:
    p = (p + 1) / 2
    head = Q.popleft()
    now = now - head + p
    Q.append(p)
    max_ = max(max_, now)

print(max_)
        

Measured memory_bytes: 25692
# -*- coding: utf-8

X = map(int, raw_input().split())

W = X[0]
H = X[1]
x = X[2]
y = X[3]
r = X[4]

if x >= r:
   if y >= r:
      if W >= x+r:
         if H>= y+r:
            print('Yes')
         else:
            print('No')
      else:
         print('No')
   else:
      print('No')
else:
   print('No')




Measured memory_bytes: 4652
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
//マスの情報
char a[555][555];
//マスごとに到達可能かそうでないかの真偽
bool b[555][555];
ll h, w, ans = 0;
ll white = 0, black = 0;
//(x,y)から任意のマスにいけるかどうかを調べる関数
void search(ll x, ll y) {
	b[x][y] = true;
	if (a[x][y] == '.')white++;
	else black++;
	//上下左右に隣り合うマスを続けて調べる(異なるマスだった場合のみ）
	if (a[x][y] != a[x][y - 1] && y >= 1 && !b[x][y - 1])search(x, y - 1);
	if (a[x][y] != a[x - 1][y] && x >= 1 && !b[x - 1][y])search(x - 1, y);
	if (a[x][y] != a[x + 1][y] && x < h - 1 && !b[x + 1][y])search(x + 1, y);
	if (a[x][y] != a[x][y + 1] && y < w - 1 && !b[x][y + 1])search(x, y + 1);
}
signed main(){
	cin >> h >> w;
	rep(i, h) { rep(j, w)cin >> a[i][j]; }
	rep(i, h) {	
		rep(j, w) {
			if (b[i][j])continue;
			if (a[i][j] == '#') {
				search(i, j);
			}
			ans += white * black;
			white = 0, black = 0;
		}
	}
	cout << ans << endl;
	ggr
}

Measured memory_bytes: 15616
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100001
#define INFINITY 1000000001

typedef struct{
  char P;
  int number;
}Card;

void mergeSort(Card *, int, int);
void merge(Card *, int, int, int);
int partition(int, int);
void quicksort(int ,int);

Card M[MAX], C[MAX];//構造体変数

int main(){
  int i, n;
  int flag = 1, count = 0;
  Card temp;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf(" %c%d", &C[i].P, &C[i].number);
  }

  //マージソートで安定な配列を確保！
  for(i = 0; i < n; i++){
    M[i] = C[i];
  }
  mergeSort(M, 0, i);

  quicksort(0, n-1);

  for(i = 0; i < n; i++){
      if(M[i].P == C[i].P){
          count++;
      }else{
          printf("Not stable\n");
          break;
      }

      if(count == n) printf("Stable\n");
  }

  for(i = 0; i < n; i++){
      printf("%c %d\n", C[i].P, C[i].number);
  }

  return 0;
}

void quicksort(int p,int r){
  int q;

  if(p < r){
    q = partition(p, r);
    quicksort(p, q - 1);
    quicksort(q + 1, r);
  }
}


int partition(int p, int r){
  int i, j;
  int x;
  Card temp;

  x = C[r].number;
  i = p - 1;

  for(j = p; j <= r - 1; j++){
    if(C[j].number <= x ){
      i = i + 1;
      temp = C[i];
      C[i] = C[j];
      C[j] = temp;
    }
  }

  temp = C[i + 1];
  C[i + 1] = C[r];
  C[r] = temp;

  return i + 1;
}

void merge(Card *M,int  left,int mid,int right){
  int i, j, k, n1, n2;
  Card L[250001],R[250001];

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0;i <= n1-1; i++){
    L[i] = M[left + i];//L[0...n1]を作成中なう
  }

  for(i = 0;i <= n2-1; i++){
    R[i] = M[mid + i];//R[0...n2]を作成中なう
  }

  L[n1].number = INFINITY;
  R[n2].number = INFINITY;

  i = 0;
  j = 0;

  for(k = left;k <= right-1; k++){
    if(L[i].number <= R[j].number){
      M[k] = L[i];
      i = i + 1;
    }else{
      M[k] = R[j];
      j = j + 1;
    }
  }
}

void mergeSort(Card *M,int left,int right){
  int mid;
  
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(M, left, mid);
    mergeSort(M, mid, right);
    merge(M, left, mid, right);
  }
}



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

int main() {
  int x;
  double a,b,d;
  cin>>a>>b;
  x=(a+b)/2;
  d=(a+b)/2;
  
  if(d==x){
    cout<<x<<endl;
  }
  else{
    cout<<x+1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

vi d;
vi* dijkstra(v(vp) &G,int V,int s) {
// G[f][i] = P(t,c) means that from `f` to `t` 's cost is `c` 
  d = vi(V,INF);
  priority_queue<P,vp, greater<P>> que;
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int tar = p.second;
    if(d[tar] < p.first) continue;
    rep(i,sz(G[tar])) {
      P e = G[tar][i];
      if(d[e.first] > d[tar] + e.second) {
        d[e.first] = d[tar] + e.second;
        que.push(P(d[e.first],e.first));
      }
    }
  }
  return &d;
}
  
int main() {
  int N,M;
  cin >> N >> M;
  v(vp) G(3*N);
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(P(b+N,1));
    G[a+N].push_back(P(b+2*N,1));
    G[a+2*N].push_back(P(b,1));
  }
  int s,t;
  cin >> s >> t;
  s--;
  t--;
  dijkstra(G,3*N,s);
  if(d[t] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << d[t]/3 << endl;
  return 0;
}

Measured memory_bytes: 17792
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
const int64_t INF=10000000000000000;
#include <vector>
#include<cstdint>
#include <iostream>
#include <vector>

template<class T>
void read_1d(std::vector<T>& a,int64_t num){
	a.reserve(num);
	for(int64_t i1=0;i1<num;i1++){
		T temp;
		std::cin>>temp;
		a.push_back(temp);
	}
}
template<class T>
void read_2d(std::vector<std::vector<T> >&a,int64_t x,int64_t y ){
	a.resize(x);
	for(int64_t i1=0;i1<x;i1++){
		a[i1].reserve(y);
		for(int64_t i2=0;i2<y;i2++){
			char temp;
			std::cin>>temp;
			if(temp=='0'){
				a[i1].push_back(0);
			}else{
				a[i1].push_back(1);
			}
		}
	}
}
template<class InputIterator>
void debug(InputIterator first,InputIterator last){
	for(auto i1=first;i1!=last;i1++){
		std::cout<<(*i1);
	}
}
int main(){
	int64_t n;
	cin>>n;
	vector<int64_t> c;
	read_1d(c,n);
	vector<int64_t> sum;
	sum.resize(2000000);
	fill(sum.begin(),sum.end(),0);
	int64_t ans=1;
	sum[c[0]]=1;
	int64_t mod=1000000007;

	for(int64_t i1=1;i1<n;i1++){
		if(c[i1-1]==c[i1]){

		}else{
			int64_t sum_copy=sum[c[i1]];
			sum[c[i1]]+=ans;
			sum[c[i1]]=sum[c[i1]]%mod;

			ans+=sum_copy;
			ans=ans%mod;
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
#define X ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// long long p = 1e9+7;

typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll, ll> pi;
typedef unordered_map<ll, ll> UMP;
#define FOR(i,b) for(i=0;i<b;i++)
#define pb push_back


void printa(VI &x,ll n){
    ll i;
    FOR(i, n){
        cout<<x[i]<<" ";
    }
    cout<<endl;
}


/////GLOABLS VARS
map <ll,ll> memo;
ll n,a,b,c,d;
map <ll, ll> cost;
//////FUNCTIONS
ll solve(ll n){
    // debug(n, memo);
    if(n==0){return 0;};
    if(n==1){return d;};
    if(memo.count(n)) return memo[n];
    VI tmp = {2,3,5};

    ll res = 1e18;
    if (n < res/d) res = n*d;
    ll ori = n;
    for(ll x:tmp){
        n = ori;
        ll m = (n/x)*x;
        res = min(res, solve(m/x)+llabs(m-n)*d+cost[x]);
        m = ((n+x-1)/x)*x;
        res = min(res, solve(m/x)+llabs(m-ori)*d+cost[x]);
    }
    memo[ori]=res;
    return res;

}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #endif
    ll tc;  cin>>tc;
    while(tc--){
        cin>>n>>a>>b>>c>>d;
        memo.clear();
        cost.clear();
        cost[2] = a;
        cost[3] = b;
        cost[5] = c;
        cout<<solve(n)<<endl;
        }
}

// 2000000000
// 2
// 3
// 2
// 1000000001
// 3
// 1000010000
// 7394836

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

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

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

  for (int i = n-1; i >= 0; i--) {
    if (i != n-1) {
      cout << " ";
    }
    cout << digits[i];
  }
  cout << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String no = sc.nextLine();
        String str = sc.nextLine();
        String[] strArraySub = str.split(" ");
        int[] box = new int[strArraySub.length];
        for(int i=0;i<strArraySub.length;i++){
            box[i]=Integer.parseInt(strArraySub[i]);
        }
        int max=0;
        int min=Integer.MAX_VALUE;
        for(int i=0;i<box.length;i++){
            max=Math.max(max, box[i]);
        }

        for(int i=0;i<box.length;i++){
            min=Math.min(min, box[i]);
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 21844