akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/perl
use Math::BigInt;

while (<>) {
    ($n, $m) = split /\s+/, $_;
}

$s = 1000000007;
if ($n == $m) {
    $r = ((k($n) % $s) * (k($m) % $s) * 2) % $s;
} elsif (abs($n - $m) == 1) {
    $r = (k($n) % $s) * (k($m) % $s) % $s;
} else {
    $r = 0;
}
print "$r\n";

sub k {
    my ($n) = @_;
    my $r = 1;
    while ($n > 1) {
        $r *= $n;
        $r = $r % $s;
        $n--;
    }
    return $r;
}


Measured memory_bytes: 4480
s = input()
n = int(input())
query = [0]*n
rev = 0
for i in range(n):
    query[i] = list(map(str, input().split()))
    if query[i][0] == '1':
        rev = rev + 1

begin = ''
end = ''
pal = 0

for i in range(n):
    if int(query[i][0]) == 1:
        pal = (pal+1)%2
    else:
        if pal == 0:
            if int(query[i][1]) == 1:
                begin = query[i][2] + begin 
            else:
                end = end + query[i][2]
        else:
            if int(query[i][1]) == 1:
                end = end + query[i][2] 
            else:
                begin = query[i][2] + begin
#    print('--------'+str(i+1)+'th try-----')
#    print('begin:'+begin)
#    print('end:'+end)
#    print('pal:'+str(pal))
if rev%2 == 1:
    print(end[::-1]+s[::-1]+begin[::-1])
else:
    print(begin+s+end)

Measured memory_bytes: 41332
N = int(input())

ans = N - 1
for i in range(2,N):
    n = N
    if N % i == 0:
        n = N - 1
    
    #print(str(i) + " " + str(n//i))
    ans += n//i
    #print(str(i) + " " + str(n // i) + " " + str(N - (i * (n//i))))

print(ans)

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

constexpr int MOD = 1e9 + 7;
int sum(int a, int b, int mod=MOD) {
    int c = a + b;
    if (c >= mod) {
        c -= mod;
    }

    return c;
}

inline int prod(int a, int b, int mod=MOD) {
    return (1LL * a * b) % mod;
}

int modpow(int base, int exp, int mod=MOD) {
    int res = 1;
    int cur = base;
    for (int p = 1; p <= exp; p <<= 1) {
        if (p & exp) {
            res = prod(res, cur, mod);
        }

        cur = prod(cur, cur, mod);
    }

    return res;
}

inline int inv(int x, int mod=MOD) {
    return modpow(x, mod - 2, mod);
}

constexpr int MAXN = 1e6 + 6;
int fact[MAXN], tcaf[MAXN];
void gen_fact() {
    fact[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        fact[i] = prod(fact[i - 1], i);
    }

    tcaf[MAXN - 1] = inv(fact[MAXN - 1]);
    for (int i = MAXN - 2; i >= 0; --i) {
        tcaf[i] = prod(tcaf[i + 1], i + 1);
    }
}

int choose(int n, int k) {
    assert(n >= 0);
    assert(0 <= k and k <= n);

    return prod(fact[n], prod(tcaf[k], tcaf[n - k]));
}

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

    gen_fact();

    // x = a + 2b
    // y = 2a + b
    // How many ways are there?

    int x, y;
    cin >> x >> y;
    int ans = 0;
    for (int a = 0; a <= x; ++a) {
        if ((x - a) % 2 != 0) continue;
        int b = (x - a) / 2;
        if (x == a + 2 * b and y == 2 * a + b) {
            ans += choose(a + b, a);
        }
    }

    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 8064
n = int(input())
a = sorted(list(int(input()) for _ in range(n)))

if n%2==0:
    ans = 2 * (sum(a[n//2:]) - sum(a[:n//2]))
    ans += a[n//2-1] - a[n//2]
    print(ans)
elif n%2!=0:
    ans = 2 * (sum(a[n//2+1:]) - sum(a[:n//2]))
    print(ans - min(a[n//2+1] - a[n//2], a[n//2] - a[n//2-1]))

Measured memory_bytes: 14156
//
// Created by swift on 2020/8/2.
//

#include<bits/stdc++.h>
using namespace std;
int n,d,ans;
int main(){
    scanf("%d%d",&n,&d);
    for(int i=1;i<=n;i++){
        double a,b;
        scanf("%lf%lf",&a,&b);
        if(sqrt(a*a+b*b)<=d){
           ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3868
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] scores = new int[n];

      int sum = 0;
      for(int i = 0; i < n; i++) {
        scores[i] = sc.nextInt();
        sum += scores[i];
      }
      if(sum % 10 == 0) {
        Arrays.sort(scores);
        int i = 0;
        for(; i < n; i++) {
          if(scores[i] % 10 != 0)
            break;
        }
        if(i == n) {
          System.out.println(0);
        } else {
          System.out.println(sum - scores[i]);
        }
        return;
      }
      System.out.println(sum);
  }

}


Measured memory_bytes: 21844
s = input()
n = len(s)
l = (n-1)//2
r = (n+3)//2
if s == s[::-1] and s[0:l] == s[0:l][::-1] and s[r-1:n] == s[r-1:n][::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,a,b;
 string s;
 cin>>s;
 for(int i=0;i<3;i++){
 	if(s.at(i)=='1'){
    	a++;
    }
 }
 cout<<a<<endl;
 
 return 0;
 }

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

bool pairCompare(const std::pair<int, int>& firstElem, const std::pair<int, int>& secondElem) {
  return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        typedef pair<int, int> value_type;
        vector<value_type> team;
        int c, m, s;
        for(int j=0; j < n; j++){
            cin >> c;
            team.push_back(pair<int, int>(c, 0));
            for(int i=0; i < 4; i++){
                cin>> m >> s;
                team[j].second += 60*m + s;
            }
        }
        sort(team.begin(), team.end(), pairCompare);

        cout << team[0].first << endl;
        cout << team[1].first << endl;
        cout << team[team.size()-2].first << endl;
        team.clear();
    }
}

Measured memory_bytes: 1304
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)

void arg_marge(int *, int *, int);

int main(void)
{

    int n, d, a, i, k, l, *x, *h, p, *pp, ppp;
    long long int at = 0;

    scanf("%d %d %d", &n, &d, &a);
    x = (int *)malloc(n * sizeof(int));
    h = (int *)malloc(n * sizeof(int));
    pp = (int *)malloc(n * sizeof(int));
    rep(i, n)
    {
        scanf("%d %d", x + i, h + i);
        h[i] = (h[i] + a - 1) / a;
    }
    arg_marge(x, h, n);

    p = 0;
    ppp = 0;
    rep(i, n)
    {
        l = x[i] - d - d;
        while (x[p] < l)
            ppp -= pp[p++];
        pp[i] = max(h[i] - ppp, 0);
        at += pp[i];
        ppp += pp[i];
    }
    printf("%lld", at);
}

void arg_marge(int *a, int *b, int n)
{

    if (n == 1)
        return;

    int *tmp, *arg_tmp;
    tmp = (int *)malloc((n) * sizeof(int));
    arg_tmp = (int *)malloc((n) * sizeof(int));
    arg_marge(a, b, n / 2);
    arg_marge(a + n / 2, b + n / 2, n - n / 2);

    for (int i = 0; i < n / 2; i++)
    {
        tmp[i] = a[i];
        arg_tmp[i] = b[i];
    }
    for (int i = n / 2; i < n; i++)
    {
        tmp[i] = a[n / 2 + n - i - 1];
        arg_tmp[i] = b[n / 2 + n - i - 1];
    }

    int lp = 0, rp = n - 1, p = 0;
    int l3, r3;
    while (p < n)
    {
        l3 = tmp[lp];
        r3 = tmp[rp];
        if (l3 < r3)
        {
            a[p] = l3;
            b[p] = arg_tmp[lp];
            lp++;
            p++;
        }
        else
        {
            a[p] = r3;
            b[p] = arg_tmp[rp];
            rp--;
            p++;
        }
    }

    return;
}


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

using namespace std;
using pii = pair<int, int>;

string S;

int cnt = 0;

int rec(int l, int r)
{
    vector<pii> v;
    int len = 0;
    bool bracket = false;
    int num = 0;
    for (int i = l + 1; i < r; i++)
    {
        len++;
        if (S[i] == '[')
        {
            bracket = true;
            num++;
        }
        else if (S[i] == ']')
        {
            num--;
        }
        if (num == 0)
        {
            v.push_back(make_pair(i - len + 1, i));
            len = 0;
        }
    }
    if (!bracket)
    {
        int n = stoi(S.substr(l + 1, r - l - 1));
        return n / 2 + 1;
    }
    vector<int> nums;
    for (int i = 0; i < v.size(); i++)
    {
        nums.push_back(rec(v[i].first, v[i].second));
    }

    int res = 0;

    sort(nums.begin(), nums.end());
    for (int i = 0; i < (nums.size() + 1) / 2; i++)
    {
        res += nums[i];
    }
    return res;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        cin >> S;
        cout << rec(0, S.size() - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3308
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    int64_t K,X;

    scanf("%"PRId64"%"PRId64, &K, &X);

    for (int64_t i = X - K + 1; i <= X + K - 1; i++) {
        printf("%"PRId64, i);
        if (i < X + K - 1) {
            putchar(' ');
        }
    }

    return 0;
}


Measured memory_bytes: 128
/*  ex4_3
    pptenshi  */

#include<stdio.h>

int num_west_tower(int height_west, int height_east);
int height_tower(int num);

int main(void) {
    int height_west,  // a 
        height_east,  // b
        snowfall;     // 積雪量

    // input
    scanf("%d%d", &height_west, &height_east);

    // calculate ans
    snowfall = height_tower(
            num_west_tower(height_west, height_east)
        ) - height_west;
    
    // output
    printf("%d\n", snowfall);

    return 0;
}

int num_west_tower(int height_west, int height_east) {
    return height_east - height_west - 1;
}

int height_tower(int num) {
    return num * (num + 1) / 2; 
}

Measured memory_bytes: 128
package main

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

type intQueue []int

func (queue *intQueue) enqueue(i int) {
	*queue = append(*queue, i)
}

func (queue *intQueue) dequeue() int {
	result := (*queue)[0]
	*queue = (*queue)[1:]
	return result
}

func main() {
	defer flush()

	n := readInt()
	q := readInt()

	result := make([]int, n)
	links := make([][]int, n)

	for i := 0; i < n-1; i++ {
		a := readInt() - 1
		b := readInt() - 1
		links[a] = append(links[a], b)
		links[b] = append(links[b], a)
	}

	for i := 0; i < q; i++ {
		p := readInt() - 1
		x := readInt()
		result[p] += x
	}

	processed := make([]bool, n)
	processed[0] = true
	var queue intQueue = make([]int, 0)
	queue.enqueue(0)
	for len(queue) != 0 {
		i := queue.dequeue()
		for _, j := range links[i] {
			if processed[j] {
				continue
			}
			result[j] += result[i]
			processed[j] = true
			queue.enqueue(j)
		}
	}

	for i := 0; i < len(result); i++ {
		println(result[i])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 30572
N = gets.to_i
names = N.times.map { gets.chomp }

counts = {
  m: names.select { |name| name[0] == "M" }.size,
  a: names.select { |name| name[0] == "A" }.size,
  r: names.select { |name| name[0] == "R" }.size,
  c: names.select { |name| name[0] == "C" }.size,
  h: names.select { |name| name[0] == "H" }.size
}

puts "march".chars.combination(3).to_a.inject(0) { |sum, comb|
  sum += comb.map { |c| counts[c.to_sym] }.inject(:*)
}


Measured memory_bytes: 10588
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s.length() < 4){
    cout << "No" << endl;
    return 0;
  }
  if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false)
void solve() {
	int d, t, s;
	cin >> d >> t >> s;
	if (t * s >= d) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}
int main() {
	solve(); 
	return 0;
}


Measured memory_bytes: 3636
x=int(input())

sosu=[]

i=2
import math

while 1:
    sqrt_i =int(math.sqrt(i))

    flag=0
    for item in sosu:
        if item>sqrt_i:
            break
        if i%item==0:
            flag=1
            break

    if flag==0:
        sosu.append(i)
        if i>=x:
            print(i)
            exit()
    i+=1
    



    

Measured memory_bytes: 3304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc096_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int[,] m = new int[HW[0] + 2, HW[1] + 2];

            for (int h = 0; h < HW[0]; h++)
            {
                var l = Console.ReadLine();
                for (int w = 0; w < HW[1]; w++)
                    if (l[w] == '#') m[h + 1, w + 1] = 1;
            }

            bool r = true;

            for (int h = 1; h <= HW[0]; h++)
            {
                for (int w = 1; w <= HW[1]; w++)
                {
                    if (m[h, w] == 1 && m[h - 1, w] == 0 && m[h, w - 1] == 0 && m[h + 1, w] == 0 && m[h, w + 1] == 0)
                    {
                        r = false;
                        break;
                    }
                }
                if (!r) break;
            }

            Console.WriteLine(r ? "Yes" : "No");

        }
    }
}


Measured memory_bytes: 11328
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 1e3 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
//-------------head-------------
int vis[4];
char S[N];
int main() {
	scanf(" %s", S);
	memset(vis, 0, sizeof(vis));
	for (int i = 0; S[i]; ++i)
		rep(j, 0, 4)
			if (S[i] == "NESW"[j]) {
				vis[j] = 1;
				break;
			}
	if ((vis[0] ^ vis[2]) || (vis[1] ^ vis[3])) {
		puts("No");
	} else {
		puts("Yes");
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

bool solve(){
    int n, smax=0, smin=INF, sum=0, s;
    cin >> n;
    if(!n) return false;
    REP(i,n){
        cin >> s;
        smax = max(s, smax);
        smin = min(s, smin);
        sum += s;
    }
    cout << (sum - smin - smax) / (n-2) << endl;
    return true;
}

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

    while(solve());
}

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


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            double N = double.Parse(ReadLine());
            for (double h = 1; h <= 3500; h++)
            {
                for (double n = 1; n <= 3500; n++)
                {
                    double hoge = (N*h*n)/((4*h*n)-(N*n)-(N*h));
                    if (is_int(hoge) && hoge > 0)
                    {
                        WriteLine(h+" "+n+" "+hoge);
                        return;
                    }
                }
            }
        }

        static bool is_int(double n)
        {
            if (n == (int)n)
            {
                return true;
            }
            else return false;
        }
    }
}


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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 6e6 + 100;
const int mod = 1e9 + 7;

void hey ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main ()
{
	hey();
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = min(a, d);
	d -= min(a, d);
	d -= min(d, b);
	ans -= min(c, d) * 1;
	cout << ans;
}



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

int main() {

    for (int i = 1; i <= 9; i++){
        cout << i << "x1=" << i*1 << endl;
        cout << i << "x2=" << i*2 << endl;
        cout << i << "x3=" << i*3 << endl;
        cout << i << "x4=" << i*4 << endl;
        cout << i << "x5=" << i*5 << endl;
        cout << i << "x6=" << i*6 << endl;
        cout << i << "x7=" << i*7 << endl;
        cout << i << "x8=" << i*8 << endl;
        cout << i << "x9=" << i*9 << endl;
    }
    return 0;
}

Measured memory_bytes: 1116
#include<utility>
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int n,m,h,d;
vector<string> F;
bool judge(vector<string> f){
int now = m;
for(int i=0;i<f.size();i++){
assert(now!=0);
if(f[i][now-1]=='1'){
now = now-1;
}else if(f[i][now]=='1'){
now = now+1;
}
//cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
}
return now == h;
}
pair<int,int> solve(){
if(judge(F))return make_pair(0,0);
for(int i=0;i<F.size();i++){
for(int j=1;j<F[i].size()-1;j++){
vector<string> tmp = F;
if(tmp[i][j-1]!='1'&&tmp[i][j+1]!='1'){
tmp[i][j]='1';
if(judge(tmp)){
return make_pair(i+1,j);
}
}
}
}
return make_pair(-1,0);
}
int main(){
while(cin>>n,n!=0){
cin>>m>>h>>d;
F.clear();
for(int i=0;i<d;i++){
string s;
cin>>s;
s = "*"+s+"*";
F.push_back(s);
}
pair<int,int> ans = solve();
if(ans.first==0){
cout<<0<<endl;
}else if(ans.first==-1){
cout<<1<<endl;
}else{
cout<<ans.first<<" "<<ans.second<<endl;
}
}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
struct UnionFind{
	vector<int> par,rank;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) swap(x,y);

		//x becomes root
		par[y]=x;
		if(rank[x]==rank[y]) rank[x]++;
	}
};

bool solve(){
	int N;
	ll M;
	int Q;
	cin >> N >> M >> Q;
	UnionFind UF(N);
	
	using P = pair<int,int>;
	V<P> ones;
	bool is1 = false;
	rep(i,Q){
		int a,b,c;
		cin >> a >> b >> c;
		if(c == 0){
			UF.unite(a,b);
		}else{
			is1 = true;
			ones.emplace_back(a,b);
		}
	}
	for(P p: ones){
		if(UF.same(p.fs,p.sc)) return false;
	}
	V<int> cnt(N);
	rep(i,N) cnt[UF.find(i)]++;
	V<ll> s;
	rep(i,N) if(cnt[i]){
		s.pb(cnt[i]);
	}
	show(s);
	if(is1 && (int)s.size() <= 2){
		return false;
	}
	if(is1 && M == N-1){
		return false;
	}
	ll MAX_M = (ll)(s.size()) * (s.size()-1) / 2;
	for(ll x: s){
		MAX_M += x-1;
	}
	return MAX_M >= M;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	if(solve()) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

const int INF = 2000000000;


int main() {
    int n;
    cin >> n;
    vector<int> H(100005);
    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }

    int dp[100005];
    for (int i = 0; i < n; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 2e5 + 7;
// dp[i] denotes the maximum beauties of the reamining flowers if we consider all flowers to
// the left of i;
ll Table[N];

void update(int i , ll val){
    while(i < N){
        Table[i] = max(Table[i] , val);
        i += i&-i;
    }
}
ll query(ll i){
    ll mx = 0;
    while(i){
        mx = max(mx , Table[i]);
        i -= i&-i;
    }
    return mx;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n; cin >> n;
    int H[n+1] , A[n+1];

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

    ll dp[n+1];
    dp[0] = 0;
    ll ans = 0;
    for(int i = 1;i <= n; i++){
        dp[i] = A[i] + query(H[i]);
        update(H[i] , dp[i]);
        ans = max(ans , dp[i]);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s;
    int n,a,b,c,d;
    cin >> a >> b >> c;
    if(a+b+c >= 22)
    {
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };


int main() {
	ll h, w, ans = INF;
	cin >> h >> w;
	if (w % 3 == 0 || h % 3 == 0)ans = 0;
	else {
		for (int i = 1; i < h; i++) {
			ans = min(ans, max(w*i, (w / 2 + w % 2)*(h - i)) - min(w*i, (w / 2)*(h - i)));
		}
		for (int i = 1; i < w; i++) {
			ans = min(ans, max(h*i, (h / 2 + h % 2)*(w - i)) - min(h*i, (h / 2)*(w - i)));
		}
		ans = min(ans, min(h, w));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<vector>
#include<limits.h>
#include<functional>
#include<stack>
#include<map>
#include<unordered_map>
typedef long long ll;
#pragma GCC optimize(2)
#define maxn 3100
#define lowbit(x) x & -x
#define endl '\n'
using namespace std;
int n, x, y;
int w[maxn];
vector<int> e[maxn];
bool flag[maxn];
void dfs(int u, int fa) {
	flag[u] = false;
	for (auto v : e[u]) {
		if (v == fa || w[u] <= w[v])
			continue;
		dfs(v, u);
		if (!flag[v]) {
			flag[u] = true;
			break;
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> w[i];
	for (int i = 1; i < n; i++) {
		cin >> x >> y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) {
		dfs(i, 0);
		if (flag[i])
			cout << i << ' ';
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  string s; cin >> s;
  ll ans = s.size();
  rep(i,s.size()-1){
    if(s[i] != s[i+1]){
      ans = min(ans,max(i+1, (ll)s.size()-i-1));
    }
  }
  cout << ans << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define mod 			1000000007
#define siz 			105
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
	ll n,i,j;
	cin>>n;
	ll a[n],b[n],c[n];
	
	for(i = 0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
		
		if(!i)
		continue;
		
		a[i] += max(b[i-1],c[i-1]);
		
		b[i] += max(a[i-1],c[i-1]);
		
		c[i] += max(a[i-1],b[i-1]);
	}
	
	cout<<max(a[n-1],max(b[n-1],c[n-1]))<<endl;
	
	
	
	
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  cout << "ABC" + s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.00000001
#define prid(x) printf("%.15lf\n", x)

double w, r[12];
int hd, dt[12];
double dp[4100][12];

bool solve(void){
  int i, j, k;
  rep(i, 1 << hd)rep(j, hd)dp[i][j] = 2016.0;
  rep(j, hd)dp[1 << j][j] = r[j];
  rep1(i, 1 << hd)rep(j, hd)if(dp[i][j] != 2016.0)rep(k, hd)if((i & (1 << k)) == 0)
  dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + 2.0 * sqrt(r[j] * r[k]));
  rep(j, hd)if(dp[(1 << hd) - 1][j] + r[j] <= w + eps)return true;
  return false;
}

int pt;
string s;

double nxt(void){
  int res = 0;
  for(;;){
    if(s[pt] == ' ')break;
    res = (res * 10) + (s[pt++] - '0');
  }
  return (double)res;
}

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    getline(cin, s);
    if(s.size() == 0)break;
    s += " ";
    hd = 0; pt = 0;
    w = nxt(); ++pt;
    for(;pt < s.size();){
      r[hd++] = nxt();
      ++pt;
    }

    puts(solve() ? "OK" : "NA");

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;

  vector<int> p(n);
  REP(i, n) {
    cin >> p[i];
  }

  deque<int> dqmin, dqmax;
  vector<int> smin;
  vector<int> smax;

  REP(i, n) {
    while (dqmin.size() > 0 && p[i] < p[dqmin.back()]) dqmin.pop_back();
    while (dqmax.size() > 0 && p[i] > p[dqmax.back()]) dqmax.pop_back();
    dqmin.push_back(i);
    dqmax.push_back(i);
    if (i < k - 2) {
      continue;
    }
    smin.push_back(p[dqmin.front()]);
    smax.push_back(p[dqmax.front()]);
    if (i - k + 2 == dqmin.front()) {
      dqmin.pop_front();
    }
    if (i - k + 2 == dqmax.front()) {
      dqmax.pop_front();
    }
  }
  int cnt = 0;
  int same = 0;
  int last = n;
  int ans = n - k + 1;
  REP(i, n) {
    if (p[i] < last) {
      cnt = 1;
    } else {
      cnt++;
    }
    last = p[i];
    if (cnt >= k) {
      same = 1;
      ans--;
    } else if (i >= k) {
      if (p[i - k] < smin[i - k + 1] && p[i] > smax[i - k + 1]) {
        ans--;
      }
    }
  }
  ans += same;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n;
    cin >> n;
    vector <ll> a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    
    ll sum =a[0];
    ll index = 1;
    rep(i,2,n) {
        sum += a[index];
        if(i %2 == 1) index++;
    }
    cout << sum << endl;
}

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

using namespace std;

long long n, W, v[107], w[107], dp[107][100007];

int main() {
	for ( int i = 0; i < 107; i++ ) 
		for ( int j = 0; j < 100007; j++ )
			dp[i][j] = 1e17;
	cin >> n >> W;
	for ( int i = 1; i <= n; i++ ) {
		cin >> w[i] >> v[i];
		dp[i][v[i]] = w[i];
	}
	for ( int i = 1; i <= n; i++ ) {
		for ( int j = 0; j <= 100000; j++ ) {
			dp[i][j] = min( dp[i - 1][j], dp[i][j]);
			if ( j >= v[i] ) {
				dp[i][j] = min( dp[i][j], dp[i - 1][j - v[i]] + w[i] );
			}
		}
	}
	int ans = 0;
	for ( int i = 0; i <= 100000; i++ ) {
		if ( dp[n][i] <= W ) 
			ans = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 83968
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t; cin >> t;
    for (int i = 0; i < t; ++i) {
        printf("Case %d:\n", i+1);
        int x;
        cin >> x;
        for (int j = 0; j < 10; ++j) {
            int nxt = (x*x)/100%10000;
            cout << nxt << "\n";
            x = nxt;
        }
    }

    return 0;
}


Measured memory_bytes: 3220
//02
#include<iostream>

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  int p[101]={};
  while(k--){
    int a,b;
    cin>>a>>b;
    p[a]=b;
  }
  int v[101][4][4]={{{}}};
  int ct;
  for(int i=1;i<=n;i++){
    ct=0;
    for(int j=1;j<=3;j++){
      if(!p[i]||j==p[i]){
	if(i==1){
	  v[1][j][0]=1;
	  ct++;
	}else{
	  for(int k=1;k<=3;k++){
	    if(i==2){
	      v[2][j][k]+=v[1][k][0];
	      ct+=v[1][k][0];
	    }else{
	      for(int l=1;l<=3;l++){
		if(!(j==k&&k==l)){
		  v[i][j][k]=(v[i][j][k]+v[i-1][k][l])%10000;
		  ct=(ct+v[i-1][k][l])%10000;
		}
	      }
	    }
	  }
	}
      }
    }
  }
  cout<<ct<<endl;
  return 0;
}

Measured memory_bytes: 1164
"use strict";

var main = function main(input) {
  var args = input.split(' ');
  var A = parseInt(args[0], 10);
  var B = parseInt(args[1], 10);
  var C = parseInt(args[2], 10);
  var D = parseInt(args[3], 10);
  var result = 0;

  if (C <= B && A <= D) {
    if (B >= D) {
      if (A >= C) {
        result = D - A;
      } else {
        result = D - C;
      }
    } else {
      if (A >= C) {
        result = B - A;
      } else {
        result = B - C;
      }
    }
  }

  console.log(result);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

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


int main() {

    int a, b;
    cin >> a >> b;
    if (a*b % 2 == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
K = int(input())

d = [[] for i in range(12)]

for i in range(1, 10):
    d[1].append(i)

if K <= 9:
    print(K)
    exit()

cur = K - 9

for i in range(2, 12):
    for t in d[i - 1]:
        r = t % 10
        if r == 0:
            d[i].append(t * 10)
            d[i].append(t * 10 + 1)
        elif r == 9:
            d[i].append(t * 10 + 9)
            d[i].append(t * 10 + 8)
        else:
            d[i].append(t * 10 + r - 1)
            d[i].append(t * 10 + r)
            d[i].append(t * 10 + r + 1)

    d[i].sort()

    if cur <= len(d[i]):
        print(d[i][cur - 1])
        exit()

    cur -= len(d[i])


Measured memory_bytes: 50544
/*
	Swamy Saranam

	Date	: 14/09/2016 22:45:26
	Author	: Krishna Mohan A M
	Problem	:
	Status	:
*/
#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FASTIO          ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back
#define x               first
#define y               second
#define endl            "\n"
#define sendl           " \n"

const int mod = 1000000007;
ll n, tmp;
ll ans;
vector<ll> dat;

int main()
{
    FASTIO
    cin>>n;
    dat.resize(n+3, 0);
    REP(i, n){
      cin>>dat[i+1];
      //ans += tmp/2;
    }
    REP(i, dat.size()-1){
      ans += dat[i]/2;
      dat[i]%=2;
      if(dat[i]&&dat[i+1]){
        ans++;
        --dat[i];
        --dat[i+1];
      }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
# 最終的に出力するリスト
answer = []

# 変数
shuffle_count = 0
card_str = ""
card_len = 0
new_index = 0
new_str = []

while True:
    # 各フェーズの文字列読み込み
    card_str = input()
    if card_str == "-":
        break
    card_len = len(card_str)

    # シャッフル回数読み込み
    shuffle_count = int(input())

    # シャッフル回数分、数値を読み込む
    new_index = 0
    for i in range(shuffle_count):
        new_index += int(input())

    # 上記のシャッフル回数を文字列の長さで剰余をとる
    new_index %= card_len

    new_str = []
    # カードをローテート
    for i in range(card_len):
        new_str.append(card_str[new_index])
        new_index += 1
        if new_index >= card_len:
            new_index = 0

    # answerリストに格納
    answer.append(new_str)

# 最終出力
for line in answer:
    print("".join(line))



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

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

    int2(a, b);
    int2(c, d);
    Int(data);

    int ret = INF;

    b = min(b, a+a);
    c = min(c, b+b);
    d = min(d, c+c);

    int ans = 0, tmp, num = data;
    tmp = num / 2; ans += tmp * d; num %= 2;
    tmp = num / 1; ans += tmp * c;
    std::cout << ans << std::endl;




    return 0;
}






Measured memory_bytes: 256
let () =
  let hash = Hashtbl.create 1000000 in
  let n = read_int ()
  in
  let rec read = function
      0 -> ()
    | i ->
       let (op, key) = Scanf.scanf "%s %s\n" (fun x y -> (x,y)) in
       if op = "insert" then
         Hashtbl.add hash key key
       else
         if Hashtbl.mem hash key then Printf.printf "%s\n" "yes"
         else Printf.printf "%s\n" "no"
       ;read (i-1)
  in read n;;

Measured memory_bytes: 44168
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;

// #define DEBUG

class Unionfind
{
    vector<int> p;

public:
    Unionfind(int n);
    int find(int x);
    void unite(int x, int y);
    bool match(int x, int y);
};

Unionfind::Unionfind(int n)
{
    for (int i = 0; i < n; i++)
    {
        p.push_back(i);
    }
}

int Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

bool Unionfind::match(int x, int y)
{
    return (find(x) == find(y)) ? true : false;
}

void Unionfind::unite(int x, int y)
{
    x = Unionfind::find(x);
    y = Unionfind::find(y);
    if (x != y)
    {
        p[x] = y;
    }
}

void printsubset(int x)
{
    int t;
    cout << x << ":";
    t = 0;
    while (x > 0)
    {
        if (x % 2 == 1)
            cout << " " << t;
        x /= 2;
        t++;
    }
    cout << endl;
}

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, t, x, op;
    cin >> n >> q;
    queue<int> a[n];
    for (int i = 0; i < q; i++)
    {
        cin >> op;
        if (op == 0)
        {
            cin >> t >> x;
            a[t].push(x);
        }
        else if (op == 1)
        {
            cin >> t;
            if (!a[t].empty())
                cout << a[t].front() << endl;
        }
        else if (op == 2)
        {
            cin >> t;
            if (!a[t].empty())
                a[t].pop();
        }
    }

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 4292
#include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define inf pow(100, 4) + 1

int dp[100][100] = {};
int n;
int getMCM(int r[], int c[])
{
    int k;
    for (int i = 1; i < n; i++)
    {
        k = 0;
        for (int j = i; j < n; j++)
        {
            dp[k][j] = inf;
            for (int l = k; l < j; l++)
            {
                dp[k][j] = min(dp[k][j], dp[k][l] + dp[l + 1][j] + r[k] * c[j] * c[l]);
            }
            k++;
        }
    }
    return dp[0][n - 1];
}

int main()
{
    cin >> n;
    int r[n], c[n];
    for (int i = 0; i < n; i++)
        cin >> r[i] >> c[i];

    cout << getMCM(r, c) << "\n";
    return 0;
}


Measured memory_bytes: 3152
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
int main()
{
	const double PI=acos(-1.0);
	double a, b, h, m; cin>>a>>b>>h>>m;
	double s=(m+h*60)/2/180*PI, t=6*m/180*PI;
	double x1=a*cos(s), y1=a*sin(s), x2=b*cos(t), y2=b*sin(t);
	x1-=x2, y1-=y2;
	printf("%.10lf\n", sqrt(x1*x1+y1*y1));
	return 0;
}

Measured memory_bytes: 4152
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int sum = 0;
    foreach(i; 0..10) sum += readln.chomp.to!int;
    sum.writeln; 
}

Measured memory_bytes: 2484