akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int main(){
  int a[3]; REP(i,3){cin >>a[i];}
  sort(a,a+3);
  int r;
  if(a[0]<a[1]){r = a[0];}
  else{r = a[2];}
  printf("%d\n",r);
}

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

int ConvStrToInt(char c)
{
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}

int main() {
	string S;
	cin >> S;

	int countR_0 = 0;
	int countL_0 = 0;
	int countR_1 = 0;
	int countL_1 = 0;
	for (int i = 0; i < S.length(); ++i)
	{
		if (i % 2 == 0)
		{
			// 左
			int tmp = ConvStrToInt(S[i]);
			if (tmp == 0) 
			{
				++countL_0;
			}
			else if (tmp == 1)
			{
				++countL_1;
			}
		}
		else
		{
			// 右
			int tmp = ConvStrToInt(S[i]);
			if (tmp == 0)
			{
				++countR_0;
			}
			else if (tmp == 1)
			{
				++countR_1;
			}

		}
	}

	int totalCharNum = 0;
	totalCharNum = S.size();
	
	int numR = totalCharNum / 2;
	int numL = totalCharNum / 2 + totalCharNum % 2;

	int resultValue = 0;
	if (max(countR_0, countR_1) < max(countL_0, countL_1))
	{
		if (countL_0 < countL_1)
		{
			// 左に1の出る数が多い = 「10101010...」と並ぶ
			int changeR = numR - countR_0;
			int changeL = numL - countL_1;
			resultValue = changeL + changeR;
		}
		else
		{
			// 右に1の出る数が多い = 「01010101...」と並ぶ
			int changeR = numR - countR_1;
			int changeL = numL - countL_0;
			resultValue = changeL + changeR;
		}
	}
	else
	{
		if (countR_0 < countR_1)
		{
			// 右に1の出る数が多い = 「01010101...」と並ぶ
			int changeR = numR - countR_1;
			int changeL = numL - countL_0;
			resultValue = changeL + changeR;
		}
		else
		{
			// 右に1の出る数が多い = 「10101010...」と並ぶ
			int changeR = numR - countR_0;
			int changeL = numL - countL_1;
			resultValue = changeL + changeR;
		}
	}

	cout << resultValue << endl;

	return 0;
}


Measured memory_bytes: 512
import numpy as np
import math

N = int(input())

a = list(map(int, input().split()))

avr = np.average(a)

av1 = math.floor(avr)
av2 = math.ceil(avr)

res1 = 0
res2 = 0

for num in a:
    res1 += (num - av1) ** 2
    res2 += (num - av2) ** 2

print(min(res1, res2))

Measured memory_bytes: 27212
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef long long ll;


ll N, M, X;
ll C[13];
ll A[13][13];
ll maxAj[13];
ll cmax;

int main() {
	int i, j, k;

	cin >> N >> M >> X;

	for (i = 0; i < N; i++) {
		cin >> C[i];
		cmax += C[i];
		for (j = 0; j < M; j++) {
			cin >> A[i][j];
			maxAj[j] += A[i][j];
		}
	}


	for (j = 0; j < M; j++) {
		if (maxAj[j] < X) {
			cout << "-1" << endl;
			exit(0);
		}
	}

	ll cmin = cmax;
	ll select;

	for (select = 1; select < (1 << (N)); select++) {
		ll cost = 0;
		ll u[13] = { 0, };
		for (i = 0; i < N; i++) {
			if (((select >> i) & 1) == 1) {
				cost += C[i];
				//cout << "select=" << i << " ";

				for (j = 0; j < M; j++) {
					u[j] += A[i][j];
				}
			}
		}
		//cout << " cost=" << cost << " " << cmin << endl;
		
		int success = 0;
		for (j = 0; j < M; j++) {
			if (u[j] >= X) success++;
		}

		if (success == M && cost < cmin) cmin = cost;
	}
	cout << cmin << endl;
}


Measured memory_bytes: 3196
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from collections import deque
from math import ceil
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = f()

b = deque([a[0]])
i = 0
if n % 2 == 0:
    for i, v in enumerate(a[1:]):
        if i % 2 == 0:
            b.appendleft(v)
        else:
            b.append(v)
else:
    for i, v in enumerate(a[1:]):
            if i % 2 == 0:
                b.append(v)
            else:
                b.appendleft(v)
    
print(*b, sep=' ')

Measured memory_bytes: 25652
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 

using namespace std;
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int x;
    cin>>x;
    cout<<1-x;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
using namespace std;

struct Com
{
    int b,c;
}com[100010];

bool operator < (Com A,Com B)
{
    return A.c>B.c;
}

int n,m,a[100010];
int t[100010],tot;
long long ans;

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d",&com[i].b,&com[i].c);
    }
    sort(com+1,com+m+1);
    for (int i=1;i<=m;i++)
    {
        for (int j=1;j<=com[i].b;j++)
        {
            t[++tot]=com[i].c;
            if (tot==n) break;
        }
        if (tot==n) break;
    }
    for (int i=1;i<=n;i++)
    {
        ans+=(long long)max(a[i],t[i]);
    }
    printf("%lld",ans);
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size
#define inf 1e9+5
 
 
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)cin>>arr[i];
        ll ans=0;
    for(ll i=0;i<n;i++){

        for(ll j=i+1;j<n;j++){
            ans+=(arr[i]*arr[j]);
        }
    }
    cout<<ans;


    

    return 0;  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
long na=scan.nextInt();
long nb=scan.nextInt();
  
long sum=1;
  for(long i=1;i<(na+nb)/2;i++){
      if((na%i==0)&&(nb%i==0)){
          sum=i;
      }
  }
System.out.println(na*nb/sum);
  
}
}


Measured memory_bytes: 21844
<?php
fscanf(STDIN, "%d", $n);
$i = 1;
$res = "";
do {
 $x = $i;
 if ($x % 3 === 0) {
    $res .= " $i";
  } else {
    do {
      if ( $x % 10 === 3) {
        $res .= " $i";
        break;
      } else {
        $x /= 10;
      }
    } while ( $x );
  }
} while (++$i <= $n);
echo $res,PHP_EOL;

Measured memory_bytes: 15252
class Node():
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

class Tree():
    def __init__(self):
        self.root = None
        self.list = []

    def insert(self, node):
        y = None                 # x's parent    
        x = self.root
        while x is not None:
            y = x                # set parent
            if node.key < x.key:
                x = x.left
            else:
                x = x.right
        node.parent = y

        if y is None:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

    def find(self, key):
        node = self.root
        while node is not None and key != node.key:
            if key < node.key:
                node = node.left
            else:
                node = node.right
        
        return node

    def parse_inorder(self, node):
        if node is None:
            return 
        self.parse_inorder(node.left)
        self.list.append(node.key)
        self.parse_inorder(node.right)

    def parse_preorder(self, node):
        if node is None:
            return
        self.list.append(node.key)
        self.parse_preorder(node.left)
        self.parse_preorder(node.right)

N = int(input())
T = Tree()
for i in range(N):
    order, *key = input().split()
    if order == "print":
        T.list = []
        T.parse_inorder(T.root)
        print(" " + " ".join(map(str, T.list)))
        T.list = []
        T.parse_preorder(T.root)
        print(" " + " ".join(map(str, T.list)))
    elif order == "find":
        node = T.find(int(key[0]))
        if node is not None:
            print("yes")
        else:
            print("no")
    else:
        node = Node(int(key[0]))
        T.insert(node)



Measured memory_bytes: 118536
#include <stdio.h>
#include <math.h>
 
int main()
{
  int a,b,c;
  double S,L;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  S=a*b*sin(c*M_PI/180)/2;
  L=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c*M_PI/180))+a+b;
  printf("%lf\n",S);
  printf("%lf\n",L);
  printf("%lf\n",2*S/a);
  return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	ll R = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				int a = L[i];
				int b = L[j];
				int c = L[k];
				if (a + b > c && a + c > b && b + c > a && a != b && a != c && b != c) {
					//cout << a << " " << b << " " << c << endl;
					R++;
				}
			}
		}
	}
	cout << R << endl;
}



Measured memory_bytes: 3656
#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// flagを用いたバブルソート
int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}


Measured memory_bytes: 2088
<?php
fscanf(STDIN, "%d %d", $x, $n);
$array = explode(' ', trim(fgets(STDIN)));

if (!isset($array)) {
  echo $x;exit;
}

$nums = range(0, 101);
foreach ($array as $v) {
  unset($nums[$v]);
}

$array = array_values($nums);

$lef = -1;
$rig = count($array);

while ($rig - $lef > 1) {
  $mid = ceil($lef + ($rig - $lef) / 2);
  if ($array[$mid] > $x) {
    $rig = $mid;
  } else {
    $lef = $mid;
  }
}

if (!isset($array[$rig]) || abs($array[$lef] - $x) <= abs($array[$rig] - $x)) {
  echo $array[$lef];
} else {
  echo $array[$rig];
}


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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007LL
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class T>
string to_string(unordered_set<T> s) {
  string ret = "{";
  for (T t : s) ret += to_string(t) + ",";
  ret += "}";
  return ret;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  K--;
  vector<vector<ll>> dp(H + 1, vector<ll>(W));
  vector<ll> len(W);
  len[0] = len[1] = 1;
  FORIN(i, 2, W) len[i] = len[i - 2] + len[i - 1];
  dp[0][0] = 1;
  FORIN(i, 1, H + 1) {
    FOR(j, W) {
      dp[i][j] += dp[i - 1][j] * len[j] * len[W - j - 1];
      if (j > 0) dp[i][j] += dp[i - 1][j - 1] * len[j - 1] * len[W - j - 1];
      if (j < W - 1) dp[i][j] += dp[i - 1][j + 1] * len[j] * len[W - j - 2];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[H][K] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;    // N <= 1e5
    set<int> nums;
    // setを使えば探索および追加は高々 O(logN)
    // 総計算量は O(NlogN)
    for (int i = 0; i < N; ++i)
    {
        int ai; cin >> ai;
        auto itr = nums.find(ai);
        if (itr == nums.end())
        {
            nums.insert(ai);
        }
        else
        {
            nums.erase(itr);
        }
    }
    cout << nums.size() << endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();

#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}

auto z_algorithm(const string &s) {
	int n = s.size(), i = 1, j = 0, k;
	vector<int> z(n, n);
	while (i < n) {
		while (i + j < n && s[i + j] == s[j]) j++;
		z[i] = j, k = !!j;
		while (i + k < n && k + z[k] < j) z[i + k] = z[k], k++;
		i += k + !j, j -= k;
	}
	return z;
}

bool is_good_string(const vector<int> &z,int len){
	if(len == 1) return true;
	if(1 + z[1] >= len) return false;

	for(int j = 2; j * j <= len; ++j) {
		if(len % j) continue;
		if (j + z[j] >= len) return false;
		const int k = len / j;
		if (k + z[k] >= len) return false;
	}

	return true;
}

int main(void){
	string s;
	cin >> s;
	const int n = s.size();

	bool all_same = true;
	rep(i,n) if(s[0] != s[i]) all_same = false;

	if (all_same) {
		cout << n << endl;
		cout << 1 << endl;
		return 0;
	}

	vector<int> z = z_algorithm(s);
	reverse(begin(s),end(s));
	vector<int> rz = z_algorithm(s);
		
	bool one = true;
	rep(p,2,n){
		if (n % p) continue;
		if(p + z[p] == n) {
			one = false;
		}
	}

	if (one) {
		cout << 1 << endl;
		cout << 1 << endl;
	} else {
		cout << 2 << endl;
		int ans = 0;
		rep(i,1,n){
			// [0, i) [i, n)
			const int fst = i;
			const int snd = n - i;
			const bool fst_res = is_good_string(z,fst);
			const bool snd_res = is_good_string(rz,snd);
			//error(fst,snd,fst_res,snd_res);
			ans += (fst_res && snd_res);
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if (a <= k){
        cout << "0" << "\n";
        if (b - (k - a) < 0) cout << "0" << "\n";
        else cout << b - (k - a) << "\n";
    }else{
        cout << a - k << "\n";
        cout << b << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int res = 0;
	for (int i = d; i <= r; i += d)
	{
		if (i >= l && i <= r) ++res;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((100 * r + 10 * g + b) % 4 == 0) {
        cout << "YES" << endl;
    }
    else if ((100 * r + 10 * g + b) % 4 != 0){
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3632
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int64) int64 {
	if a <= b {
		return a
	}
	return b
}

func main() {
	defer write.Flush()

	var n, a, b int64
	fmt.Fscan(read, &n, &a, &b)

	cnt := n / (a + b) * a
	n %= a + b
	cnt += min(a, n)

	fmt.Fprintln(write, cnt)
}


Measured memory_bytes: 640
X = int(input())

def nb(b):
    if b == 0:
        return 1
    elif b > 0:
        return -b
    else:
        return -b+1

b = 0

def fac(x):
    if x>=0:
        return x**0.2
    else:
        return -(-x)**0.2

while 1:
   
# for i in range(1):
    # print("b:",b)
    a_est = int(fac(b**5+X))
    if a_est**5-b**5==X:
        a = a_est
        break
    elif (a_est+1)**5-b==X:
        a = a_est+1
        break
    
    # print(a_est)
    b = nb(b)

print(a,b)


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

using namespace std;

int p[8], q[8], _p[8], _q[8];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		_p[i] = p[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> q[i];
		_q[i] = q[i];
	}

	sort(_p, _p + n);
	sort(_q, _q + n);

	int a = 1, b = 1;
	bool match;
	do {
		match = true;
		for (int i = 0; i < n; ++i) {
			if (p[i] != _p[i]) {
				match = false;
				++a;
				break;
			}
		}
		if (match) break;
	} while (next_permutation(_p, _p + n));

	do {
		match = true;
		for (int i = 0; i < n; ++i) {
			if (q[i] != _q[i]) {
				match = false;
				++b;
				break;
			}
		}
		if (match) break;
	} while (next_permutation(_q, _q + n));

	cout << abs(a - b) << '\n';
	return 0;
}

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

pass_student = 0
B_pass_student = 0
for i in range(N):
  if S[i] == "a" and pass_student < AB:
    print("Yes")
    pass_student +=1
  elif S[i] =="b" and pass_student < AB and B_pass_student < B:
    print("Yes")
    pass_student += 1
    B_pass_student += 1
  else:
    print("No")

Measured memory_bytes: 75932
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 2e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	bool pos = false, neg = false;
	vector<ll> a(n);
	ll sum = 0, mi = INF;
	rep(i,n){
		cin >> a[i];
		if(a[i] >= 0){
			pos = true;
			chmin(mi, a[i]);
			sum += a[i];
		}
		if(a[i] <= 0){
			neg = true;
			chmin(mi, -a[i]);
			sum -= a[i];
		}
	}
	sort(a.rbegin(), a.rend());
	ll ans = sum;
	if(!pos || !neg) ans -= 2 * mi;
	cout << ans << endl;
	ll x = a[0], y = a[n-1];
	for(int i = 1; i < n-1; ++i){
		if(a[i] < 0){
			cout << x << " " << a[i] << endl;
			x -= a[i];
		}
		else{
			cout << y << " " << a[i] << endl;
			y -= a[i];
		}
	}
	cout << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 3952
#include<cstdio>
#include<vector>
#include<iostream>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#define eps 1e-10
using namespace std;
int a[100005],sum[100005],md[100006];
map<int,int> m;
int cnt[100005],tot;
main()
{
    int N,S,W,Q;
    while(scanf("%d%d%d%d",&N,&S,&W,&Q),N+S+W+Q)
    {
        memset(cnt,0,sizeof(cnt));tot=0;
        m.clear();
        int g = S;
        for(int i=0; i<N; i++) {
            a[i] = (g/7) % 10;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }
        if(Q==2||Q==5)
        {
            int cur=0,ans=0;
            for(int i=0;i<N;i++)
            {
                if(a[i]!=0) cur++;
                if(a[i]%Q==0) ans+=cur;
            }
            printf("%d\n",ans);continue;
        }
        for(int i=0;i<N/2;i++) swap(a[i],a[N-1-i]);
        md[0]=1;
        for(int i=1;i<100005;i++) md[i]=md[i-1]*10%Q;
        sum[0]=a[0]%Q;m[sum[0]]=++tot;
        for(int i=1;i<N;i++)
        {
            sum[i]=(a[i]*md[i]+sum[i-1])%Q;
            if(m[sum[i]]==0) m[sum[i]]=++tot;
        }
        int ans=0;
        for(int i=N-1;i>=0;i--)
        {
            ans+=cnt[m[sum[i]]];
            if(a[i]!=0) cnt[m[sum[i]]]++;
        }
        ans+=cnt[m[0]];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 6860
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    temp=0
    max=sum(p[0:k])
    maxi=0
    temp=max
    if n>=2:
        for i in range(1,n-k+1):
            temp-=p[i-1]
            temp+=p[i+k-1]
            if temp>max:
                max=temp
                maxi=i
    total=(max+k)/2
#    for i in range(maxi,maxi+k):
 #       total+=(1+p[i])

    print(total)

if __name__ == "__main__":
    main()

Measured memory_bytes: 71760
package main

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

func main() {
	fmt.Printf("%f\n", resolve(parseProblem(os.Stdin)))
}

type city struct{ x, y int }

func parseProblem(r io.Reader) (cities []city) {
	var n int
	fmt.Fscanf(r, "%d", &n)
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for i := 0; i < n; i++ {
		x := scanInt(sc)
		y := scanInt(sc)
		cities = append(cities, city{x, y})
	}
	return cities
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

func resolve(cities []city) float64 {
	l := len(cities)
	sum := 0.0
	num := 0
	for p := range permutations(l) {
		sum += length(p, cities)
		num++
	}
	return sum / float64(num)
}

func length(perm []int, cities []city) float64 {
	l := len(perm)
	var sum float64
	for i := 0; i < l-1; i++ {
		sum += dist(cities[perm[i]], cities[perm[i+1]])
	}
	return sum
}

func dist(s, t city) float64 {
	return math.Sqrt(math.Pow(float64(s.x-t.x), 2) + math.Pow(float64(s.y-t.y), 2))
}

func permutations(l int) chan []int {
	ch := make(chan []int)
	go func() {
		dfsPermutations(0, make([]bool, l), []int{}, func(perm []int) bool {
			p := make([]int, len(perm))
			copy(p, perm)
			ch <- p
			return false
		})
		close(ch)
	}()
	return ch
}

func dfsPermutations(pos int, used []bool, perm []int, atLeaf func(perm []int) (halt bool)) (halt bool) {
	l := len(used)
	if pos == l {
		if atLeaf(perm) {
			return true
		}
	}

	for i := 0; i < l; i++ {
		if used[i] {
			continue
		}
		used[i] = true
		if dfsPermutations(pos+1, used, append(perm, i), atLeaf) {
			return true
		}
		used[i] = false
	}
	return false
}


Measured memory_bytes: 3712
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
import math

if n==3:
    print(2,5,63)
    exit()

a = [2,3,5]
now = 30000

for i in range(n-3):
    if i == n-4:
        total = sum(a)
        m = now
        while True:
            if (total+now)%30 == 0 and math.gcd(total,now) > 1:
                a.append(now)
                break
            if now < 6:
                if a[-1]%2==0:
                    a[-1]-=2
                elif a[-1]%3==0:
                    a[-1]-=3
                elif a[-1]%5==0:
                    a[-1]-=5
                total = sum(a)
                now = m+1
            now-=1
    else:
        while True:
            if now%2 == 0 or now%3 == 0 or now%5 == 0:
                a.append(now)
                now-=1
                break
            now-=1

print(*a)

Measured memory_bytes: 10112
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

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

    sort(a, a + n);

    int ai = a[n - 1];

    double half = (double) (ai) / 2;
//    cout << half << endl;
    int aj;
    int ajdiff = 1000000000;
    for (int i = 0; i < n - 1; ++i) {
        double diff = abs((double) (a[i]) - half);
//        cout << diff << endl;
        if (diff < ajdiff) {
            aj = a[i];
            ajdiff = diff;
        }
    }

    cout << ai << " " << aj << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    cout << lcm(2, n) << endl;
}


Measured memory_bytes: 3656
n, mxcnt, ans = int(input()), int(), 1

for i in range(1, n + 1):
    cnt = 0
    ii = i
    while (ii / 2) >= 1:
        ii /= 2
        cnt += 1
    if cnt > mxcnt:
        mxcnt = cnt
        ans = i

print(ans)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define YES(c) if(c)co("YES");else co("NO")
#define Yes(c) if(c)co("Yes");else co("No")
#define yes(c) if(c)co("yes");else co("no")
#ifdef LOCAL_tqk
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

bool f(int n){
    if((n/10000 == n%10)&&((n/1000)%10 == (n%100)/10)) return 1;
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    lint n;
    cin>>n;
    co(n/3);
}

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

int main() {
  int N,col=3;
  cin >> N;
  for(int i=0;i<N;i++){
    char s;
    cin >> s;
    if(s == 'Y'){
      col++;
      cout << "Four" << endl;
      break;
    }
  }
  if(col == 3){
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
v=list(input().split())
v1=v[0:n:2]
v2=v[1:n:2]
import collections
c1=collections.Counter(v1)
a1=c1.most_common()[0][0]
a2=(c1.most_common()[1][0] if len(c1)>=2 else 0)
c2=collections.Counter(v2)
b1=c2.most_common()[0][0]
b2=(c2.most_common()[1][0] if len(c2)>=2 else 0)
if a1!=b1:
    cou=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou+=1
    print(cou)
else:
    cou1=0
    for i in range(n//2):
        if v1[i]!=a2:
            cou1+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou1+=1
    cou2=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou2+=1
    for i in range(n//2):
        if v2[i]!=b2:
            cou2+=1
    print(min(cou1,cou2))


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

int main(){
    /*偶数回数字が出ると消えるので、
    奇数回出てきた文字の種類を数えればよい*/
    int n, a;
    cin >> n;
    map<int, int> num;
    for (int i=0; i<n; i++) {
        cin >> a;
        //キーaのマップが空でなければ１を足す
        if (num.find(a) != num.end()) {
            num[a] += 1;
        }
        //空なら１にする
        else {
            num[a] = 1;
        }
    }
    //ansは奇数回出てきた個数
    int ans = 0;
    //マップ配列を全て取り出す
    for (auto itr: num) {
        /*itr.firstでキーを、itr.secondで値を取り出せる
        値は出現回数なので奇数ならansに１を足す*/
        if (itr.second % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;

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

		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();

			if(H==0||W==0){
				break;
			}
			for ( int i = 0; i < H; i++ ){
				for ( int j = 0; j < W; j++ ){
					System.out.print("#");
		    }
				System.out.println("");
		}


		System.out.println("");
		}
		sc.close();
	}
}


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

int main(){
    int n;
    cin >> n;
    int a1[n+1];
    int a2[n+1];
    int dp1[n+1];
    int dp2[n+1];
    for(int i = 1; i <= n; i++){
        cin >> a1[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> a2[i];
    }
    dp1[1] = a1[1];
    for(int i = 2; i <= n; i++){
        dp1[i] = dp1[i-1] + a1[i];
    }
    dp2[n] = a2[n];
    for(int i = n-1; i >= 1; i--){
        dp2[i] = dp2[i+1] + a2[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, dp1[i] + dp2[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
	int d;
	while(std::cin >> d){
		int sum = 0, num = 600 / d;
		for(int i = 1 ; i <= num - 1 ; ++i){
			sum += (d * (d * d * i * i));
		}
		std::cout << sum << std::endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
#define f(i,x,y,z) for(int i=x;i<y;i+=z)
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
ll gcd(ll,ll);
ll lcm(ll,ll);
bool prime(ll x);
ll fp(ll b,ll p,ll m);
ll inv(ll a,ll m);
int main(){
    fast;
    int n;
    cin>>n;
    ll arr[n];
    int flag=0;
    f(i,0,n,1) {
        cin >> arr[i];
        if (arr[i] == 0) {
            flag = 1;
        }
    }
    if(flag==1){
        cout<<"0\n";
        exit(0);
    }
    ll x=1000000000000000000;
    ll now=1;
    f(i,0,n,1){
        if(arr[i]<=x/now) {
            now = now * arr[i];
        }
        else{
            flag=1;
            break;
        }
    }
    if(flag==1){
        cout<<"-1\n";
    }
    else{
        cout<<now<<'\n';
    }
}
ll gcd(ll x,ll y) { return (y==0)? x: gcd(y,x%y);}
ll lcm(ll x, ll y) { return (x*y)/gcd(x,y);}
ll inv(ll a,ll m){return fp(a,m-2,m);}
bool prime(ll x){
    if(x<2) return false;
    if(x<4) return true;
    if(x%2==0 or x%3==0) return false;
    f(i,5,sqrt(x)+1,6)
        if(x%i==0 or x%(i+2)==0) return false;
    return true;
}
ll fp(ll b,ll p,ll m){
    b%=m;
    ll res=1;
    while(p>0){
        if(p%2==1)
            res=(res*b)%m;
        b=(b*b)%m;
        p=p/2;
    }
    return res%m;
}

Measured memory_bytes: 4480
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

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

    string s =  (x< 1200 ? "ABC" : "ARC");
    cout << s << endl;
  
    return 0;
}



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

int main() {
    int n;
    int alice = 0;
    int bob = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(),a.end());
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            alice += a.at(i);
        }
        else {
            bob += a.at(i);
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(){
 
  int a, b;
  int ans = 0;
  
  cin >> a >> b;
  
  for(int i = a; i <= b; i++){
   	string s;
    s = to_string(i);
    if(s[0] == s[4] && s[1] == s[3]){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = (int)1e9;

int dp[1 << 18][18];

int A[18], B[18];

int n;

bool bit(int x, int p) {
    return x & (1 << p);
}

void solve() {
    scanf("%d", &n);

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

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

    for (int i = 0; i < n; ++i) {
        if (i & 1) {
            swap(A[i], B[i]);
        }
    }

    /*
    for (int i = 0; i < n; ++i) {
        printf("%d %d\n", A[i], B[i]);
    }
    */

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

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

    for (int mask = 0; mask < (1 << n); ++mask) {
        int bpop = __builtin_popcount(mask);

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

            if (bit(mask, i)) {
                int cur = (bpop % 2 ? A[i] : B[i]);
                int w = 0;

                for (int j = n - 1; j >= 0; --j) {
                    if (!bit(mask, j)) {
                        int nxt = (bpop % 2 ? B[j] : A[j]);

                        if (nxt >= cur) {
                            dp[mask + (1 << j)][j] = min(dp[mask + (1 << j)][j], dp[mask][i] + w);
                        }
                    }
                    else {
                        ++w;
                    }                
                }                
            }            
        }   
    }

    int ans = INF;

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

    if (ans >= INF) {
        ans = -1;
    }

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

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 18816
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	int a = 0, un = 0;
	for (int i = 0; i < N;i++) {
		string res; cin >> res;
		if (res == "A") a++;
		else un++;

		if (a < un) {
			cout << "NO" << endl;
			return 0;
		}
	}
	if (a == un) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>

#define MAX 2147483647

int h[100000];
int dp[100000];

void chmin(int *a,int b){
    if(*a > b){
        *a = b;
    }
}

int rec(int i){
    if(dp[i] != MAX){
        return dp[i];
    }
    if(i==0){
        return 0;
    }
    
    int res = MAX;
    chmin(&res,rec(i-1)+abs(h[i-1]-h[i]));
    if(i>1){
        chmin(&res,rec(i-2)+abs(h[i-2]-h[i]));
    }
    return dp[i]=res;
}
/*
int rec(int i){
    if(i==0){
        return 0;
    }
    
    int res = MAX;
    chmin(&res,rec(i-1)+abs(h[i-1]-h[i]));
    if(i>1){
        chmin(&res,rec(i-2)+abs(h[i-2]-h[i]));
    }
    return res;
}*/

int main(void){
    // Your code here!
    int N;
    int i;
    
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&h[i]);
        dp[i] = MAX;
    }
    printf("%d\n",rec(N-1));
    return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      int n=sc.nextInt();
      int r=sc.nextInt();
      int a=0;
      if (n<10){
        a=(100*(10-n))+r;
      }else{
        a=r;
      }
      System.out.println(a);
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, K; cin >> N >> K;
    vector<i64> V(N);
    REP(i, N) cin >> V[i];

    i64 maxv = 0;
    REP(l, K + 1) {
        for (i64 r = 0; (l + r) <= min(N, K); r++) {
            priority_queue<i64, vector<i64>, greater<i64>> jewl;
            REP(i, l) jewl.push(V[i]);
            REP(i, r) jewl.push(V[N - 1 - i]);
            REP(i, K - (l + r)) {
                if (jewl.empty()) break;
                if (jewl.top() >= 0) break;
                jewl.pop();
            }
            i64 sv = 0;
            while (!jewl.empty()) { sv += jewl.top(); jewl.pop(); }
            chmax(maxv, sv);
        }
    }

    cout << maxv << endl;

    return 0;
}

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

int main(){
  int n;
  long long ans = 0;
  cin>>n;
  for (int i = 1; i <= n; i++){
  if((i%15!=0)&&(i%5!=0)&&(i%3!=0))
    ans+=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, A, B = map(int, raw_input().split())
S = raw_input()
p, q = 0, 0
for s in S:
    if s == "a":
        if p + q < A + B:
            print "Yes"
            p += 1
        else:
            print "No"
    if s == "b":
        if p + q < A + B and q < B:
            print "Yes"
            q += 1
        else:
            print "No"
    if s == "c":
        print "No"


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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int ans[300*300+1][301];
const int mod = 998244353;
int a[300];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	ll fns = 1;
	rep(i,n) fns = 1ll*fns*3%mod;
	ans[0][0] = 1;
	int sum = 0,tsum=0;
	rep(i,n) cin>>a[i],tsum+=a[i];
	rep(i,n){
		int x;
		x = a[i];
		sum+=x;
		repD(j,min(sum,(tsum)/2),x){
			repD(k,i+1,1){
				if(j>=x) ans[j][k]  += ans[j-x][k-1];
				if(ans[j][k]>mod) ans[j][k]-=mod;
			}
		}
	}
	ll ex = 0;
	repD(j,sum,(sum+1)/2){
		int pw = 1;
		repD(k,n,0){
			if(sum%2==0&&tsum-j==sum/2) ex+=3ll*ans[tsum-j][n-k]%mod;
			fns-=3ll*ans[tsum-j][n-k]%mod*(pw)%mod;
			pw = 2ll*pw%mod;
		}
	}
	fns+=(ex);
	cout<<(fns%mod+mod)%mod;
	
	
	return 0;
}



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

public class Main {
	
    public static void main(String[] args) {
    	final long MOD = 1000000007L;
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S1 = sc.next();
        String S2 = sc.next();
        
        char[] upper = new char[N];
        char[] lower = new char[N];
        for(int i=0;i<N;i++){
        	upper[i] = S1.charAt(i);
        	lower[i] = S2.charAt(i);
        }
        int availableColors = 3;
        int n=0;
        long ans = 1;
        while(n<N){
        	if(upper[n]==lower[n]){
        		ans = (ans*availableColors)%MOD;
        		availableColors = 2;
        		n++;
        	}else{
        		if(availableColors==1)      ans = (ans*3)%MOD;
        		else if(availableColors==2) ans = (ans*2)%MOD;
        		else /*availableColors==3*/ ans = (ans*6)%MOD;
        		availableColors = 1;
        		n+=2;
        	}
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844