akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll X, Y;
    cin >> X >> Y;

    if (Y % 2 == 0 && -X + Y / 2 >= 0 && 2 * X - Y / 2 >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

namespace Reverseing_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            String[] str = Console.ReadLine().Split(' ');
            int[] ngo = new int[n];
            for (int i = 0; i < n; ++i) ngo[i] = int.Parse(str[i]);
            Array.Reverse(ngo);
            for (int i = 0; i < n - 1; ++i) Console.Write(ngo[i] + " ");
            Console.WriteLine(ngo[n - 1]);
        }
    }
}


Measured memory_bytes: 9204
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include <iomanip>
#include<queue>
#include<functional>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main() {
	int H, N,D=0; cin >> H >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A.begin(),A.begin()+N,greater<int>());
	rep(i, N) {
		D += A[i];
		if (D >= H) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;

}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

const int MAXN = 1e5 + 5;
int h[MAXN];
long long ans[MAXN];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> h[i];
		
	ans[0] = 0;
	ans[1] = h[1] - h[0];
	ans[1] = ans[1] > 0 ? ans[1] : ans[1] * -1;
	for (int i = 2; i < n; i ++) {
		int h1 = h[i] - h[i - 1];
		h1 = h1 > 0 ? h1 : h1 * -1;
		int h2 = h[i] - h[i - 2];
		h2 = h2 > 0 ? h2 : h2 * -1;
		ans [i] = min (ans[i - 1] + h1, ans[i - 2] + h2);
	}
	cout << ans[n - 1] << endl;
	return 0;
}


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

using namespace std;

#define endl "\n"
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define f first
#define s second
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007

typedef long long ll;

vector<string> v;

void rid(char ch){
    for(int i=1;i<v.size();++i){
        v[i].erase(v[i].find(ch),1);
        continue;
    }
}

bool check(char ch){

    for(int i=1;i<v.size();++i){
        if(v[i].find(ch)==string::npos)return 0;
    }
    return 1;
}

void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        string x;
        cin>>x;
        SORT(x);
        v.pb(x);
    }
    string ans="";
    for(int i=0;i<v[0].size();++i){
        if(check(v[0][i])){
            ans+=v[0][i];
            rid(v[0][i]);
        }
    }
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //int t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


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

int64_t gcd(int64_t, int64_t);
int64_t lcm(int64_t, int64_t);

int main()
{
  int64_t a, b;
  cin >> a >> b;

  cout << lcm(a, b) << endl;
  
  return 0;
}

int64_t gcd(int64_t a, int64_t b)
{
  int64_t r = a % b;
  int64_t gcd = b;
 
  int64_t tmp;
  while (r != 0)
  {
    tmp = r;
    r = gcd % r;
    gcd = tmp;
  } 
  
  return gcd;
}

// a, bの最小公倍数をL, 最大公約数をGとしたとき、LG=ab -> L=ab/G
int64_t lcm(int64_t a, int64_t b)
{
  return a * b / gcd(a, b);
}

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

#define int long long
typedef long long ll;
//const int INF = 2e9;
const ll INF = 9e18;
struct Edge {int to, cost;};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<vector<Edge>> g(N);
    vector<int> dist(N,INF);
    vector<bool> visited(N,false);
    for (int i=0;i<N-1;i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        Edge e1;
        e1.to = b;
        e1.cost = c;
        Edge e2;
        e2.to = a;
        e2.cost = c;
        g[a].push_back(e1);
        g[b].push_back(e2);
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    dist[K] = 0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,K));
    while (!q.empty()){
        pair<int,int> p = q.top();q.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (auto e : g[v]){
            if (dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to],e.to));
            }
        }
    }
    for (int i=0;i<Q;i++){
        int x, y;
        cin >> x >> y;
        x--;y--;
        cout << dist[x] + dist[y] << "\n";
    }
}

Measured memory_bytes: 14044
use std::io::{Read, stdin};
use std::str::FromStr;
use std::cmp;

fn main() {
    let w: i64 = read();
    let h: i64 = read();
    let n = read();
    let mut x_min: i64 = 0;
    let mut x_max: i64 = w;
    let mut y_min: i64 = 0;
    let mut y_max: i64 = h;

    for _i in 0..n {
        let x: i64 = read();
        let y: i64 = read();
        let a = read();
        match a {
            1 => x_min = cmp::max(x_min, x),
            2 => x_max = cmp::min(x_max, x),
            3 => y_min = cmp::max(y_min, y),
            4 => y_max = cmp::min(y_max, y),
            _ => (),
        }
    }
    let mut ans = 0;
    if y_max > y_min && x_max > x_min {
        ans = (y_max - y_min) * (x_max - x_min);
    }
    println!("{}", ans);
}


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

Measured memory_bytes: 4352
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

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

    int N;
    int a[100010];

    cin >> N;
    reps(i, 1, N) cin >> a[i];

    int cnt = 0;
    reps(i, 1, N-1) {
        if (a[i] == i) {
            swap(a[i], a[i+1]);
            ++cnt;
        }
    }
    if (a[N] == N) ++cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<pll> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<pll> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,h ;
	cin >> n >> h ;
	ll a,b ;
	a = b = 0 ;
	vector<pll> vec(n) ;
	for(int i=0;i<n;i++){
		pll sub ;
		cin >> sub.second >> sub.first ;
		vec.at(i) = sub ;
		if(a<sub.second){
			a = sub.second ;
			b = sub.first ;
		}
	}
	mysort(vec) ; myrev(vec) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		if(vec.at(i).first<=a) break ;
		ans++ ;
		h -= vec.at(i).first ;
		if(h<=0){
			cout << ans << endl ;
			return 0 ;
		}
	}
	ans += (h+a-1)/a ;
	cout << ans << endl ;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
D - ModSum
https://atcoder.jp/contests/abc139/tasks/abc139_d

"""
import sys


def solve(N):
    return (1 + (N-1)) * (N - 1) // 2


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
# 2020/01/12
# AtCoder Beginner Contest 151 - C

# Input
n, m = map(int,input().split())

# Calc
acstat = [0] * (n+1)
wa_acm = [0] * (n+1)

wk_p = -1
ac_cnt = 0
wa_cnt = 0
for i in range(m):
    p, s = input().split()
    inp = int(p)
    if s == "AC":
        if acstat[inp] == 0:
            ac_cnt = ac_cnt + 1
            wa_cnt = wa_cnt + wa_acm[inp]
            acstat[inp] = 1
        
    elif s == "WA":
        if acstat[inp] == 0:
            wa_acm[inp] = wa_acm[inp] + 1

# Output
print(ac_cnt, wa_cnt)

Measured memory_bytes: 4596
#include<stdio.h>
 
int main(){
  int a,b;

  scanf("%d", &a);
  scanf("%d", &b);
  
  if(a>b){
      printf("a > b\n");
  }
  else if(a<b){
      printf("a < b\n");
  }
  else
  printf("a == b\n");
 
  return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;

int main(int argc, const char * argv[]) {

    int n, k;
    cin >> n >> k;
    vector<long long> num(k,0);
    
    for(int i = 1; i <= n; i++){
        num[i%k]++;
    }
    long ans = 0;
    for(int a = 0; a < k; a++){
        int b = (k-a) % k;
        int c = (k-a) % k;
        if((b+c) %k != 0){
            continue;
        }
        //cout << a << "," << b << "," << c << endl;
        ans += num[a] * num[b] * num[c];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int sum = 0;
    int W[N];
    for(int i = 0; i < N; i++){
        W[i] = 0;
        cin >> W[i];
        sum += W[i];
    }

    int ans = sum;
    int S1 = 0;
    for (int i = 0; i < N - 1; i++)
    {
        S1 += W[i];
        ans = min(ans, abs(sum - S1 - S1));
    }
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] numberArray = sc.next().split("");
		int answer = 0;
		for(String number :numberArray) {
			answer += Integer.valueOf(number);
		}
		System.out.println(answer);
	}
}

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

int n;
int h[101];

int main(){
	cin >> n;
	
	for(int i=0; i<n; ++i){
		cin >> h[i];
	}
	
	int max = h[0];
	int time =1;
	for(int i=1; i<n; ++i){
		if(h[i]>=max){
			++time;
			max = h[i];
		}
	}
	
	cout << time;
	
	return 0;

}

Measured memory_bytes: 256
(defun solver ()
  (let* ((n (read)) (h (read))
         an bn amax
         (count 0))
    (loop repeat n do
          (push (read) an)
          (push (read) bn))
    (setf amax (first (sort an #'>)))
    (setf bn (remove-if (lambda (x) (> amax x)) bn))
    (setf bn (sort bn #'>))
    (loop do
          (if (not (null bn))
              (progn
                (decf h (pop bn))
                (incf count)
                (when (<= h 0) (return (format t "~a~%" count))))
              (progn
                (incf count (floor h amax))
                (when (> (mod h amax) 0) (incf count))
                (return (format t "~a~%" count)))))))

(solver)

Measured memory_bytes: 61800
#include <stdio.h>
int main()
{
  float f;
  while((scanf("%f",&f))!=EOF){
    if(f<=48.00) printf("light fly\n");
    else if(f<=51.00) printf("fly\n");
    else if(f<=54.00) printf("bantam\n");
    else if(f<=57.00) printf("feather\n");
    else if(f<=60.00) printf("light\n");
    else if(f<=64.00) printf("light welter\n");
    else if(f<=69.00) printf("welter\n");
    else if(f<=75.00) printf("light middle\n");
    else if(f<=81.00) printf("middle\n");
    else if(f<=91.00) printf("light heavy\n");
    else printf("heavy\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int sum[30], n, m, x, y;
int MAP[110][110];
int main() {
    memset(MAP, -1, sizeof(MAP));
    cin >> n >> m;
    x = y = 1;
    for (int i = 0; i < n; i ++) {
        string s; cin >> s;
        for (int j = 0; j < s.length(); j ++)
            sum[s[j] - 'a'] ++;
    }
    for (int i = 0; i < 26; i ++) {
        if (sum[i] & 1) {
            if (!(n & 1) || !(m & 1)) {
                return printf("No"), 0;
            }
            if (MAP[(n >> 1) + 1][(m >> 1) + 1] != -1) {
                return printf("No"), 0;
            }
            MAP[(n >> 1) + 1][(m >> 1) + 1] = i;
            sum[i] --;
        }
        if (sum[i] % 4 == 2) {
            if (!(n & 1) && !(m & 1)) {
                return printf("No"), 0;
            }
            int tmp = 0;
            if (m & 1)
                for (int j = 1; !tmp && j <= n / 2; j ++)
                    if (MAP[j][(m >> 1) + 1] == -1) {
                        MAP[j][(m >> 1) + 1] = i;
                        MAP[n - j + 1][(m >> 1) + 1] = i;
                        tmp = 1;
                    }
            if (n & 1)
                for (int j = 1; !tmp && j <= m / 2; j ++)
                    if (MAP[(n >> 1) + 1][j] == -1) {
                        MAP[(n >> 1) + 1][j] = i;
                        MAP[(n >> 1) + 1][m - j + 1] = i;
                        tmp = 1;
                    }
            if (!tmp) {
                return printf("No"), 0;
			}
            sum[i] -= 2;
        }
		for (int j = 1; j <= sum[i] / 4; j ++) {
			while (MAP[x][y] != -1) {
				y ++;
                if (y == (m >> 1) + 1)
                    y = 1, x ++;
			}
			MAP[x][y] = i;
			MAP[n - x + 1][y] = i;
			MAP[x][m - y + 1] = i;
			MAP[n - x + 1][m - y + 1] = i;
		}
    }
	puts("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  long long X, Y;

  std::cin >> X >> Y;

  if (X % Y == 0) {
    std::cout << -1 << std::endl;
  }
  else {
    for (long long i = X; ; i += X)
      if (i % Y) {
        std::cout << i << std::endl;

        break;
      }
  }

  return 0;
}


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

int main()
{
   string s;
   cin>>s;
   int l=s.size();
   if(s[l-1]=='3')
    cout<<"bon"<<endl;
   else if(s[l-1]=='0'||s[l-1]=='1'||s[l-1]=='6'||s[l-1]=='8')
    cout<<"pon"<<endl;
   else if(s[l-1]=='2'||s[l-1]=='4'||s[l-1]=='5'||s[l-1]=='7'||s[l-1]=='9')
   cout<<"hon"<<endl;
    return 0;
}



Measured memory_bytes: 3616
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp::{max};

fn main(){
    input!{
        a : i64,
        b : i64,
    }

    let ans1 = a + b;
    let ans2 = a - b;
    let ans3 = a * b;

    println!("{}",max(max(ans1,ans2),ans3));
}

Measured memory_bytes: 4352
n = int(input())
xyh = [list(map(int,input().split())) for _ in [0]*n]
xyh = sorted(xyh,key=lambda x:x[2])
# H-|x-Cx|-|y-Cy| = h

#全探索で良さそう
for i in range(101):
  for j in range(101):
    Cx,Cy=i,j
    #print(Cx,Cy)
    x,y,h = xyh[-1][0],xyh[-1][1],xyh[-1][2]
    H = max( h+ abs(x-Cx)+ abs(y-Cy), 0)
    if all([h==max(H-abs(x-Cx)-abs(y-Cy),0) for x,y,h in xyh]):
      print(Cx,Cy,H)
      exit()
        
        





Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

ll f(ll b, ll n){
    if(n<b)return n;
    return f(b,n/b)+n%b;
}

int main(){
    
    ll n,s; cin>>n>>s;
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }
    
    for(ll b=2;b<=sqrt(n)+1;b++){
        if(f(b,n)==s){
            cout<<b<<endl;
            return 0;
        }
    }
    
    
    ll ans=1e18;
    for(ll p=1;p<sqrt(n);p++){
        if((n-s)/p+1>=2)if(f((n-s)/p+1,n)==s){
            ans=min(ans,(n-s)/p+1);
        }
    }
    
    if(ans==1e18)cout<<-1<<endl;
    else cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

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

const ll INF = 1<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, x[3];
ll dp[41][1<<17];
int p[1<<17];

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	return res;
}

int main() {
	cin >> n;
	REP(i, 3) cin >> x[i];
	int keta = x[0] + x[1] + x[2];
	
	REP(i, 17) p[1<<i] = i;
	
	dp[0][0] = 1;
	
	REP(i, n) {
		REP(j, 1 << keta) {
			if (!dp[i][j]) continue;
			
			FOR(k, 1, 11) {
				int num = j << k | 1 << (k - 1);
				num &= (1 << keta) - 1;
				
				int now = num;
				int pos = 2, sum = 0;
				
				while (now > 0) {
					int last = p[now & -now] + 1;
					
					sum += last;
					if (sum == x[pos]) pos--, sum = 0;
					
					now >>= last;
				}
				if (pos == -1) continue;
				
				(dp[i + 1][num] += dp[i][j]) %= MOD;
			}
		}
	}
	
	ll ans = 0;
	REP(i, 1 << keta) (ans += dp[n][i]) %= MOD;
	ans = (mod_pow(10, n, MOD) - ans + MOD) % MOD;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 40704
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14

ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}
 
ll findlcm(ll arr[], ll n) { 
    ll ans = arr[0]; 
    FOR1(i, n-1) {
    	ans = ((arr[i] / (__gcd(arr[i], ans)))*ans);
    	if (ans >1000000000) return -1;
    }
    return ans; 
} 


int main() {
	ll n, m;
	cin >> n >> m;
	ll a[n];
	FOR0(i,n) {
		cin >> a[i];
		a[i]/=2;
	}
	ll lcm = findlcm(a, n);

	// cout << lcm << endl;
	if (lcm==-1){
		cout << 0;
		return 0;
	}
	ll newlcm = lcm;
	bool chk = true;
	FOR0(i,n){
		if ((newlcm/a[i])%2==0){
			chk = false;
			break;
		}
	}
	if (chk==false){
		cout << 0;
		return 0;
	}
	m-=newlcm;
	if (m<0){
		cout << 0 << endl;
		return 0;
	}
	m/=(2*newlcm);
	// m+=1;
	m+=1;
	cout << m << endl;
}
	




Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main(void){
    // Here your code !
    vector<int> x;
    while(1){
        int a;
        cin>>a;
        if(a==0)break;
        x.push_back(a);
    }
    for (int i = 0; i<x.size(); i++){
        printf("Case %d: %d\n", i+1, x[i]);
    }
    return 0;
}


Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define gog pair<int,string>
//#define cin fin
//#define cout fout
using namespace std;

//ifstream fin("joc7.in");
//ofstream fout("joc7.out");

const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

double w,h,x,y,ar;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<fixed<<setprecision(9);
	cin >> w >> h >> x >> y;
	ar=w*h;
	ar/=2;
	cout<<ar<<' ';
	if(x==w/(double)2 && y==h/(double)2) rc(1);
	rc(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,sum=0,m;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
  float k  = float(sum)/float(n);
 // cout<<k<<endl;
    float p = abs(a[n-1]-k);
    m=n-1;
    //cout<<p<<endl;
      for(i=n-2;i>=0;i--)
      {
          if(abs(a[i]-k)<=p)m=i,p=abs(a[i]-k);
      }
      cout<<m<<endl;

}


Measured memory_bytes: 256
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = [float("INF")]*n
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Measured memory_bytes: 70052
def main():
    K = int(input())
    A, B = map(int, input().split())

    for i in range(A, B+1):
        if i % K == 0:
            ans = 'OK'
            break
    else:
        ans = 'NG'

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61660
import math
N, K = map(int, input().split())
ans = 0.
rate = 1./N
for i in range(N):
  if i + 1 >= K:
    ans += rate
  else:
    ans += rate * 0.5 ** math.ceil(math.log(K / (i + 1), 2))
print(ans)

Measured memory_bytes: 3060
L=input().split()
A=int(L[0])
B=int(L[1])
K=int(L[2])
Key=[]

cnt=0

for j in reversed(range(1,max(A,B)+1)):
    if A%j==0 and B%j==0:
        Key.append(j)
        
        
print(Key[K-1])
     

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
typedef pair<int,int> P;
struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};


int main(){
  int N,M;
  cin>>N>>M;
  UnionFind UF(N);
  for(int i = 0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    UF.unite(a,b);
  }
  int ans = 0;
  for(int i = 0;i<N;i++){
    ans = max(ans,UF.size(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n;
  cin >> n;
  n /= 1000;
  char ans = n + 'C';
  cout << "AB" << ans << endl;
}

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

int main() {
  vector<int> X(5);
  for(int i=0; i<5; ++i) cin >> X[i];
  int K;
  cin >> K;
  sort(X.begin(), X.end());
  int tmp = X[4]-X[0];
  if(K<tmp) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    N = n
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    if cnt > 0:
        a.append(cnt)
    f = 3
    cnt = 0
    while f * f <= N:

        if n % f == 0:
            cnt += 1
            n //= f
        else:
            f += 2
            if cnt > 0:
                a.append(cnt)
            cnt = 0

    if n != 1:
        a.append(1)
    return a

n = int(input())
ans = 0
lis = prime_factorize(n)
#print(lis)

for i in range(len(lis)):
    val = 1
    while val <= lis[i]:
        lis[i] -= val
        val += 1
        ans += 1
print(ans)


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    int ans = 0;
    for (int i=0; i<n; ++i) cin >> p[i];
    for (int i=0; i<n-2; ++i) {
        vector<int> t(3);
        for (int j=0; j<3; ++j) {
            t[j] = p[i + j];
        }
        sort(t.begin(), t.end());
        if (p[i + 1] == t[1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = int(1e9 + 7)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	a := getInts(N)

	sum := 0
	for i := 0; i < N; i++ {
		sum += a[i]
		sum %= mod
	}

	ans := 0
	for i := 0; i < N-1; i++ {
		sum -= a[i]
		if sum < 0 {
			sum += mod
		}
		ans += a[i] * sum
		ans %= mod
	}
	out(ans)
}


Measured memory_bytes: 5848
import sys
import numpy as np


def input(): return sys.stdin.readline().rstrip()


def main():
    n, k = [int(i) for i in input().split()]
    h = np.array([int(i) for i in input().split()])
    dp = np.full(n, float('inf'))

    # 初期条件
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])

    for i in range(2, n):
        ik = max(0, i - k)
        dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

    print(int(dp[n-1]))


if __name__ == '__main__':
    main()


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

#define endl "\n"
#define PB push_back
#define F first 
#define S second
#define int long long 
#define Runner_up ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

signed main()
{	
	Runner_up
	int k,a,b; cin>>k>>a>>b;
	int flag=0;
	if(k <= b){
		int z = b - b%k;
		if(z >= a ) flag=1;
	}
	if(flag) cout<<"OK"; else cout<<"NG";
	return 0;	
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep2(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
//const ll mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

ll N, M, K, H, W, L, R;
string S, T;

int main(){
  cin >> N;
  vector<double> A(N);
  double amax = 0;
  rep(i,N) {
    cin >> A[i];
    amax = max(amax, A[i]);
  }
  double amin = amax;
  double cans;
  
  rep(i,N){
    if(A[i] == amax) continue;
    if(amin > abs(amax/2-A[i])){
      amin = abs(amax/2-A[i]);
      cans = A[i];
    }
  }
  cout << fixed << setprecision(0);
  cout << amax << " "<< cans << endl;
  return 0;
}

Measured memory_bytes: 4040
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  int n,a[20],ans=0,max=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(max<a[i]) {
      max=a[i];
    }
    if(max<=a[i]) {
      ans++;
    }
    else {
      ans+=0;
    }
  }
cout << ans << endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	ll c=1;
	rep(i,100){
		if(c>=b){
			puta(i);return 0;
		}
		c-=1;
		c+=a;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n; cin >> n;
    vector<vector<int>> g(n);
    for(int i=0;i<n-1;i++){
        int a,b; cin >> a >> b;
        a--; b--;
        g[b].push_back(a);
        g[a].push_back(b);
    }
    vector<int> c(n); rep(i,n) cin >> c[i];
    sort(c.begin(),c.end());
    int ans=0;
    rep(i,n-1) ans += c[i];
    int hasi = -1;
    rep(i,n) if(g[i].size()==1){hasi = i; break;}
    queue<int> q;
    vector<int> ap(n);
    vector<bool> cb(n); rep(i,n) cb[i] = false;
    ap[hasi] = c[n-1];
    cb[hasi] = true;
    q.push(hasi);
    int pos = n-2;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(auto x: g[t]){
            if(x!=t && cb[x]==false){
                ap[x] = c[pos];
                pos--;
                cb[x] = true;
                q.push(x);
            }
        }
    }
    cout << ans << endl;
    rep(i,n) cout << ap[i] << " ";
    cout << endl;
    return 0;
}

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

typedef unsigned long long ll;
//ll mod = 1000000007;
#define mod 1000000007

ll pow(ll m, ll n){
	  if(n==0) return 1;
	  if(n%2==1)
			return ((pow(m,(n-1)/2) % mod) * (pow(m,(n-1)/2) % mod) * (m % mod)) % mod;
	  else
			return ((pow(m,n/2) % mod) * (pow(m,n/2) % mod)) % mod;
}


ll mypow(ll m, ll n){
	  if(n==0) return 1;
	  if(n%2==1)	return mypow(m*m%mod,n/2) % mod * m % mod;
	  return mypow(m*m%mod,n/2) % mod;
}


int main(){

	  ll m,n; cin >> m >> n;
	  cout << mypow(m,n)%mod << endl;
}

Measured memory_bytes: 1156
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 

// Function to return length 
// of the resulatant number 
int numLen(int K) 
{ 

	// If K is a multiple of 2 or 5 
	if (K % 2 == 0 || K % 5 == 0) 
		return -1; 

	int number = 0; 

	int len = 1; 

	for (len = 1; len <= K; len++) { 

		// Instead of generating all possible numbers 
		// 1, 11, 111, 111, ..., K 1's 
		// Take remainder with K 
		number = (number * 10 + 1) % K; 

		// If number is divisible by k 
		// then remainder will be 0 
		if (number == 0) 
			return len; 
	} 

	return -1; 
} 

// Driver code 
int main() 
{ 

	int k;
	cin>>k;
	if(k%7==0)
	k=k/7;
	cout << numLen(k); 

	return 0; 
} 


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    for(int i=0;i<30;++i){
        if(BIT(i)&b){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    N*=2;
    int line[N];
    REP(i, N){
        cin >> line[i];
    }
    sort(line, line+N);
    int ans = 0;
    for(int i=N%2;i<N;i+=2){
        ans += line[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int total = 0;
  rep(i, n) total += min(x[i], k - x[i]) * 2;
  cout << total << endl;
}


Measured memory_bytes: 256
N=int(input())
S=input()
Cost=0
for i in range(1,N):
    if S[i]=="E":
        Cost+=1
Costtmp=Cost
for i in range(1,N):
    if S[i-1]==S[i]:
        if S[i]=="W":
            Costtmp+=1
        else:
            Costtmp-=1
    if Costtmp<Cost:
        Cost=Costtmp
print(Cost)


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

int main () {
	char s;
	int res;
	cin >> res;
	while (cin >> s, s != '=') {
		int x;
		cin >> x;
		switch (s) {
		case '+':
			res += x;
			break;
		case '-':
			res -= x;
			break;
		case '*':
			res *= x;
			break;
		case '/':
			res /= x;
			break;
		}
	}
	cout << res << endl;
	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  int res = 3;
  if(a==b || b==c || c==a) res = 2;
  if(a==b && b==c) res = 1;
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int s[30]={1,2,4};
  int n,i,y,d;
  for(i=3;i<30;i++){
    s[i]=s[i-1]+s[i-2]+s[i-3];
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    d=(s[n-1]-1)/10;
    //d++;
    y=d/365;
    y++;
    printf("%d\n",y);
  }
  return 0;
}

Measured memory_bytes: 600
import sys
import math

n, l = list(input().split())
n = int(n)
l = int(l)

all = []
for i in range(n):
    all.append(l+i)
all_sum = sum(all)

minus = 10000
ans = 0
for i in range(len(all)):
    if math.fabs(all_sum - (all_sum - all[i])) < math.fabs(minus):
        minus = math.fabs(all_sum - (all_sum -all[i]))
        ans = all_sum -all[i]
print(ans)


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

int main()
{   long long int a,b,c,d;
    cin>>a>>b>>c>>d;

    long long int temp,re=-1000000000000000000;

    temp=(a*c);
    re=max(re,temp);
    temp=(a*d);
    
    re=max(re,temp);
    temp=(b*c);
    re=max(re,temp);
    temp=(b*d);
    re=max(re,temp);
    cout<<re<<endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

// union by size + path having
class UnionFind {
public:

    //素集合の要素の親（木構造の根）を配列*3で保持している．初期状態では頂点間の辺は存在せず，孤立した状態のため，自分自身を根として初期化している（par: parent の略）．
    vector <ll> par;

    // 各集合（木）の大きさ．根をたどるとその木の大きさが返されるように実装されている．この配列を用意しておくとある頂点の連結成分の大きさを簡単に求められる
    vector <ll> siz;

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

const int MAX_V = 10000;
const int MAX_E = 100000;

struct edge {ll u, v, cost;};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

vector<edge> es(MAX_E);
ll V, E;

ll kruskal() {
    sort(es.begin(), es.begin() + E, comp);
    UnionFind uf(V);
    ll res = 0;
    rep(i, E){
        edge e = es[i];
        if(!uf.issame(e.u, e.v)) {
            uf.merge(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}


// ------------------------------------------------------------
// クラスカル法 O(|E|log|V|) 連結成分に属しているかどうかをUnionFindで検索
// ------------------------------------------------------------
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp

int main(){
    ll s, t, w;
    cin >> V >> E;
    rep(i, E){
        cin >> s >> t >> w;
        es[i] = ((edge){s, t, w});
    }
    cout << kruskal() << endl;
}


Measured memory_bytes: 5460
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]

l = [0] * 10**6
tot = 0
for i in range(N) :
    l[A[i]]+=1
    tot += A[i]
for i in range(Q):
    s0 = S[i][0]
    s1 = S[i][1]
    tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])
    l[s1] += l[s0]
    l[s0] = 0
    print(tot)

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

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

int main() {
  int n;
  cin >> n;
  int cnt[n+1];
  fill((int*)cnt, (int*)(cnt+n+1), 0);
  rep(i,n-1) {
    int t;
    cin >> t;
    cnt[t-1]++;
  }
  
  rep(i,n) cout << cnt[i] << endl;
  return 0;
}


Measured memory_bytes: 4400
a = input()
b = input()
c = input()

cur = 'a'
i1 = 0
i2 = 0
i3 = 0
while True:
    # print(cur, i1, i2, i3)
    if cur == 'a':
        if i1 == len(a):
            print('A')
            break
        else:
            cur = a[i1]
            i1 += 1
    elif cur == 'b':
        if i2 == len(b):
            print('B')
            break
        else:
            cur = b[i2]
            i2 += 1
    elif cur == 'c':
        if i3 == len(c):
            print('C')
            break
        else:
            cur = c[i3]
            i3 += 1


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

int main(){
  
  int n, q, com, b, e;
  
  cin >> n;
  vector<int> A(n);
  vector<int>::iterator a = A.begin();
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> com >> b >> e;
    if(com == 0) cout << *min_element(a + b, a + e) << endl;
    else if(com == 1) cout << *max_element(a + b, a + e) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define eb emplace_back
#define mkp make_pair
#define MOD 100000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll r,c;	cin>>r>>c;
  	ll ans=(r*c)/2;
  	if(r==1 || c==1)cout<<"1";
  	else {
      if(r%2==0 || c%2==0)cout<<ans;
  	  else cout<<ans+1;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC056ASolve solve = new ABC056ASolve();
		solve.main();
	}
}


class ABC056ASolve {
	
	char a;
	char b;
	
	ABC056ASolve() {
		Scanner cin = new Scanner(System.in);
		this.a = cin.next().charAt(0);
		this.b = cin.next().charAt(0);
	}
	
	void main() {
		char ans = 'a';
		if (a == 'H') {
			if (b == 'H') {
				ans = 'H';
			} else {
				ans = 'D';
			}
		} else {
			if (b == 'H') {
				ans = 'D';
			} else {
				ans = 'H';
			}
		}
		System.out.println(ans);
	}
	
}

Measured memory_bytes: 20820
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] Ni = new int[N];
   for(int i = 0; i<N;i++)
   {
		Ni[i] = sc.nextInt();       
   }
   int count =0;
   for(int i = 0; i<N;i++)
   {
		if(Ni[i]-1 != i) count++;
   }
   if(count <=2)System.out.println("YES");
   else System.out.println("NO");
 }
}

Measured memory_bytes: 24148