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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int a[110];

int main() {
    ll n, k;
    cin >> n >> k;
    if (k == 1 || n == 0)printf("0\n");
    else if (n <= k)printf("%lld\n", min(n % k, k - n));
    else {
        cout << min(n % k, (n / k + 1) * k - n) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $K);
$hoge = trim(fgets(STDIN));
$h = explode(" ", $hoge);

$f = [];
$f[0] = 0;
$f[1] = abs($h[1] - $h[0]);

for ($i = 2; $i < $N; $i++) {
    $min = 10000000000;
    $k = min($K, $N);
    
    for ($j = 1; $j <= $K && $i >= $j; $j++) {
        $min = min($min, $f[$i-$j] + abs($h[$i-$j]-$h[$i]));
    }
    $f[$i] = $min;
}

echo $f[$N-1]."\n";





Measured memory_bytes: 19060
from collections import deque

s = deque(input())
q = int(input())
first = 1

for i in range(q):
    t = input().split()
    if int(t[0]) == 1:
        first *= -1
    else:
        f = int(t[1])
        c = t[2]
        
        if first == 1:
            if f == 1:
                s.appendleft(c)
            elif f == 2:
                s.append(c)
        else:
            if f == 1:
                s.append(c)
            elif f == 2:
                s.appendleft(c)

S = "".join(s)
if first == 1:
    print(S)
else:
    print(S[::-1])

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int[] ans = new int[N+1];
		Arrays.fill(ans,0);
		for(int i=2;i<=N;i++){
			ans[nextInt()]++;
		}
		for(int i=1;i<ans.length;i++){
			System.out.println(ans[i]);
		}


	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 69592
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
	    Scanner sc = new Scanner(System.in);
	    String  s1 = sc.next();
	    int W = Integer.parseInt(s1);
	    String  s2 = sc.next();
	    int H = Integer.parseInt(s2);
	    String  s3 = sc.next();
	    int x = Integer.parseInt(s3);
	    String  s4 = sc.next();
	    int y = Integer.parseInt(s4);
	    String  s5 = sc.next();
	    int r = Integer.parseInt(s5);
	    String yn = "";
	    if( -100 <= x && x <= 100 ){
	    	if(-100 <= y && y <= 100 ){
	    		if(0 < W && W <= 100){
	    			if(0 < H && H <= 100){
	    				if(0 < r && r <= 100){
	                        if( x + r <= W && r <= x ){
	                            if( y + r <= H && r <= y ){
	                            	yn = "Yes";
	                            }
	                            else{
		        	                yn = "No";
	                            }
	                        }
	                        else{
	        	                yn = "No";
	                        }
	    			    }
	    			}
	    		}
	    	}
	    }
	    System.out.println( yn );
	}

}

Measured memory_bytes: 17288
Max = 100001
N = int(input())
A = list(map(int, input().split()))

Sum = 0
cnt = Max*[0]
for i in range(N):
	Sum += A[i]
	cnt[A[i]] += 1

ans = []
tmp = Sum
Q = int(input())
for i in range(Q):
	B, C = map(int, input().split())
	tmp += (C-B)*cnt[B]
	ans.append(tmp)
	cnt[C] += cnt[B]
	cnt[B] = 0

for i in range(Q):
	print(ans[i])


Measured memory_bytes: 20312
/*
 * @Autor: valk
 * @Date: 2020-07-17 16:50:40
 * @LastEditTime: 2020-09-19 20:32:30
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int seed = 12289;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int fa[N], sz[N];

int find(int x){
    if(fa[x]==x)
        return x;
    return fa[x] = find(fa[x]);
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        fa[i] = i;
        sz[i] = 1;
    }
    int ans = 1;
    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        int uu = find(u), vv = find(v);
        if (uu == vv)
            continue;
        fa[uu] = vv;
        ans = max(ans, sz[vv]+=sz[uu]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4784
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000

def bfs(lst, used, que, w, h):
  v, y, x  = pop(que)
  if y > 0 and not used[y - 1][x]:
    push(que, (lst[y - 1][x], y - 1, x))
    used[y - 1][x] = True
  if h > y + 1 and not used[y + 1][x]:
    push(que, (lst[y + 1][x], y + 1, x))
    used[y + 1][x] = True
  if x > 0 and not used[y][x - 1]:
    push(que, (lst[y][x - 1], y, x - 1))
    used[y][x - 1] = True
  if w > x + 1 and not used[y][x + 1]:
    push(que, (lst[y][x + 1], y, x + 1))
    used[y][x + 1] = True
  return v

def make_dic(lst, w, h, x, y):
  que = [(1, y, x)]
  used = [[False] * w for _ in range(h)]
  used[y][x] = True
  dic = [[0, 0]]
  app = dic.append
  Max = 0
  acc = 0

  while que:
    v = bfs(lst, used, que, w, h)
    acc += 1
    if v > Max:
      app([v, acc])
      Max = v
    else:
      dic[-1][1] += 1
  return dic

def solve():
  while True:

    R = int(input())
    if not R:
      break

    w1, h1, x1, y1 = map(int, input().split())
    x1 -= 1
    y1 -= 1
    lst1 = [list(map(int, input().split())) for _ in range(h1)]
    used1 = [[False] * w1 for _ in range(h1)]
  
    w2, h2, x2, y2 = map(int, input().split())
    x2 -= 1
    y2 -= 1
    lst2 = [list(map(int, input().split())) for _ in range(h2)]
    used2 = [[False] * w2 for _ in range(h2)]
  
    dic1 = make_dic(lst1, w1, h1, x1, y1)
    dic2 = make_dic(lst2, w2, h2, x2, y2)
  
    end1 = len(dic1)
    end2 = len(dic2)
    ind1 = 0
    ind2 = end2 - 1
    ans = INF
  
    while ind1 < end1 and ind2 > 0:
      r1, sum1 = dic1[ind1]
      r2, sum2 = dic2[ind2]
  
      if sum1 + sum2 < R:
        ind1 += 1
        continue
  
      while ind2 > 0 and sum1 + sum2 >= R:
        ind2 -= 1
        r2, sum2 = dic2[ind2]
  
      if ind2 == 0 and sum1 + sum2 >= R:
        rs = r1 + r2
        if rs < ans:
          ans = rs
        break
  
      else:
        if ind2 < end2 - 1:
          ind2 += 1
        r2 = dic2[ind2][0]
        rs = r1 + r2
        if rs < ans:
          ans = rs
  
      ind1 += 1
    print(ans)
 
solve()


Measured memory_bytes: 61880
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!{
        n: [i64; 3],
    }
    let mut n = n;
    n.sort();
    println!("{}", if n[0] == n[1] {n[2]} else {n[0]});
}


Measured memory_bytes: 4352
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll a[n], x, ans = 0, sum = 0;
    for (ll i = 0; i < n; i++) {
        cin >> x;
        a[i] = x - i - 1;
    }
    sort(a, a + n);
    ll mid = (n % 2 ? a[n / 2] : a[n / 2 - 1]);
    for (ll i = 0; i < n; i++) {
        ans += abs(a[i] - mid);
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, K;
  cin >> N >> K;
  
  int ans = 0;

  int tmp = 0;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    if(tmp >= K){
      ans++;
    }
  }

  cout << ans << endl;



  return 0;
}


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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	vi n(4);
	FOR(i,4) n[i] = ri();
	sort(all(n));
	cout << ((n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) ? "YES":"NO") << endl;
    return 0;
}


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

class Segtree {
private:
  std::vector<int> t_;
  std::vector<int> lazy_;
  int n_;
public:
  int Get(int n, int L, int R) {
    if (lazy_[n]) {
      return L - lazy_[n];
    } else {
      return t_[n];
    }
  }
  
  int Query(int n, int lft, int rgt, int rs, int re) {
    if (lft >= rs && rgt <= re)
      return Get(n, lft, rgt);
    if (lft > re || rgt < rs)
      return static_cast<int>(1e9);
    const int mid = (lft + rgt) / 2;
    if (lazy_[n]) {
      lazy_[2 * n] = lazy_[n];
      lazy_[2 * n + 1] = lazy_[n];
      lazy_[n] = 0;
    }
    int x = Query(2 * n, lft, mid, rs, re);
    int y = Query(2 * n + 1, mid + 1, rgt, rs, re);
    t_[n] = std::min(Get(2 * n, lft, mid), Get(2 * n + 1, mid + 1, rgt));
    return std::min(x, y);
  }
  
  void Set(int n, int lft, int rgt, int rs, int re, int v) {
    if (lft > re || rgt < rs)
      return;
    if (lft >= rs && rgt <= re) {
      lazy_[n] = v;
      return;
    }
    const int mid = (lft + rgt) / 2;
    if (lazy_[n]) {
      lazy_[2 * n] = lazy_[n];
      lazy_[2 * n + 1] = lazy_[n];
      lazy_[n] = 0;
    }
    Set(2 * n, lft, mid, rs, re, v);
    Set(2 * n + 1, mid + 1, rgt, rs, re, v);
    t_[n] = std::min(Get(2 * n, lft, mid), Get(2 * n + 1, mid + 1, rgt));
  }

  Segtree(int n) : 
    n_(n), 
    t_(4 * n + 1),
    lazy_(4 * n + 1) {}
};

void Run() {
  int h, w;
  cin >> h >> w;
  Segtree st(w + 1);
  for (int i = 1; i <= w; ++i) {
    st.Set(1, 1, w, i, i, i);
  }
  for (int i = 1; i <= h; ++i) {
    int a, b;
    cin >> a >> b;
    int v = - w;
    if (a > 1) {
      v = st.Query(1, 1, w, a - 1, a - 1);
      v = a - 1 - v;
    }
    st.Set(1, 1, w, a, b, v);
    int best = st.Get(1, 1, w);
    if (best > w) {
      cout << "-1\n";
    } else {
      cout << i + best << '\n';
    }
  }
}
 
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}

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


def main():
    h, n = map(int, input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]
    inf = float('inf')
    dp = [inf for _ in range(2 * 10 ** 4 + 100)]
    dp[0] = 0

    for i in range(n):
        ai, bi = map(int, input().split())
        a[i] = ai
        b[i] = bi

    for i in range(h):
        for j, ai in enumerate(a):
            if dp[i] == inf:
                continue

            dp[i + ai] = min(dp[i + ai], dp[i] + b[j])

    print(min(dp[h:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42972
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(i=0;i<Arr.length;i++){
   var arr=Arr[i].split(" ").map(Number);
   (function(x1, y1, x2, y2, x3, y3, x4, y4){
      var k1=(x2-x1==0)?Infinity:(y2-y1)/(x2-x1);
      var k2=(x4-x3==0)?Infinity:(y4-y3)/(x4-x3);
      var ans="NO";
      if(k1==0 && k2==Infinity)ans="YES";
      if(k2==0 && k1==Infinity)ans="YES";
      if(Math.abs(k1*k2+1)<1.0e-8)ans="YES";
      console.log(ans);
   }).apply(null,arr);
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    if (a < b){
        cout << "a < b" << endl;
    }else if (a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main (void){
  int a,b,c;
  std::cin >> a >>b;
  if((a==1 &&b==2 )||(a==2 &&b==1 )){cout << 3;}
  if((a==1 &&b==3 )||(a==3 &&b==1 )){cout << 2;}
  if((a==3 &&b==2 )||(a==2 &&b==3 )){cout << 1;}
return 0;
}

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

int main() {
    int n; cin >> n;
    //vector<string> s(n);
    map<string, int> mp;
    int maxv = 0;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
        maxv = max(maxv, mp[s]);
    }
    vector<string> ss;
    for (auto s : mp) {
        if (s.second == maxv) {
            ss.push_back(s.first);
        }
    }
    sort(ss.begin(), ss.end());
    for (auto s: ss) {
        cout << s << endl;
    }
}

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

int n;

int main(void){
	cin >> n;
	vector<string> w(n);
	unordered_map<string, bool> mp;
	rep(i, n) cin >> w[i];
	mp[w[0]] = true;
	for(int i = 1; i < n; i++){
		if(mp[w[i]] == true){
			cout << "No" << endl;
			return 0;
		}
		if(w[i-1][w[i-1].size()-1] != w[i][0]){
			cout << "No" << endl;
			return 0;
		}
		mp[w[i]] = true;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,m,d,n,MOD=1000000007,i,j,array[100000+10],p,q,sum=0,cnt1=0,cnt,cnt2=0,cnt3=0,flag=0,ans=0,minx,maxx;
    long long int it,st,ct,qt;
    string str,ptr;
    vector<long long int> veci;
    vector<char>vecc;
    vector<string>vecs;
    queue<long long int>vecq;
    set<long long int>si;
    cin >> n >> m;
    for (i = m; i <= n+1; i++)
    {
         minx = (i *(i - 1)) / 2;
         maxx = (i*n) - minx;
        //cout << minx << ":" << maxx << endl;
        ans += (maxx - minx + 1) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}



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

int main() {
  int n,m;
  cin >> n >> m;
  int a[m];
  int sum =0;
  rep(i,m) {
      cin >> a[i];
      sum += a[i];


  }

  if(n>=sum){
      cout << n-sum << endl;
  }

  else{
      cout << -1 << endl;
  }

  


}

Measured memory_bytes: 3672
list1=[]
while True: 
    n = int(input())
    if n == 0:
        break #n が 0 のときにループから抜ける
    else:
        for i in range(n):
            j=int(input())
            list1.append(j)
        list1.remove(max(list1))
        list1.remove(min(list1))
        print(sum(list1)//len(list1))
        list1=[]


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur;
    cin>>cur;
    ll mx = cur;
    while(--n){
      ll x;
      cin>>x;
      cur = max(x,cur+x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define ull unsigned long long int
#define gcu getchar_unlocked
#define pc(x) putchar(x);
#define pcu(x) putchar_unlocked(x);
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

//ll gcd(ll a, ll b)
//{
//    if(b==0)
//        return a;
//    else
//        return gcd(b,a%b);
//}

//void readint(ll &x)
//    {
//        bool neg=false;
//        ll c;
//        x =0;
//        c=gc();
//        if(c=='-')
//        {
//            neg = true;
//            c=gc();
//        }
//        for(;(c>47 && c<58);c=gc())
//            x = (x<<1) + (x<<3) +c -48;
//        if(neg)
//            x *=-1;
//    }
//
//inline void input(ll *n)
//{
////    register char c=getchar_unlocked();
//    *n=0;
//    for(;(c<'0'||c>'9');c=getchar_unlocked());
//    for(;(c<='9'&&c>='0');c=getchar_unlocked())
//    {
//        *n=((*n)<<1) + ((*n)<<3) + c - 48;
//    }
//}

//inline void writeInt (ll n)
//{
//    ll N = n, rev, count = 0;
//    rev = N;
//    if (N == 0) { pc('0'); pc('\n'); return ;}
//    if (N*(-1)>0){pc('-');rev=rev*(-1);N=N*(-1);}
//    while ((rev % 10) == 0) { count++; rev /= 10;}
//    rev = 0;
//    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
//    while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
//    while (count--) pc('0');


//ll power(ll x, ll y,ll p)
//{
//    ll res = 1;
//    x = x % p;
//
//    while (y > 0)
//    {
//        if (y & 1)
//            res = (res*x) % p;
//
//        y = y>>1;
//        x = (x*x) % p;
//    }
//    return res;
//}

int main()
{
    SPEED
    ll n,i;
    cin>>n;
    long double a[n],s=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s=s+(1/a[i]);
    }
    cout<<fixed<<setprecision(6)<<(1/s)<<"\n";
}


Measured memory_bytes: 256
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    a = readInt()
    s = sum(a)
    print(max(n-s,-1))
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 9884
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
    long X;
    std::cin >> X;
    std::cout << 8-(X-400)/200 << std::endl;
    return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, x) for (auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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 T > struct SparseTable { //[a, b)
    vector<vector<T> > st;
    vector< int > lookup;
    
    SparseTable(const vector<T> &v) {
        int b = 0;
        while((1 << b) <= v.size()) ++b;
        st.assign(b, vector< T >(1 << b));
        for(int i = 0; i < v.size(); i++) {
            st[0][i] = v[i];
        }

        for(int i = 1; i < b; i++) {
            for(int j = 0; j + (1 << i) <= (1 << b); j++) {
                st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
            }
        }
        
        lookup.resize(v.size() + 1);
        
        for(int i = 2; i < lookup.size(); i++) {
            lookup[i] = lookup[i >> 1] + 1;
        }
    }
        
    inline T rmq(int l, int r) {
        int b = lookup[r - l];
        return max(st[b][l], st[b][r - (1 << b)]);
    }
};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, t;
    cin >> n >> t;
    vector<int> A(n);
    rep(i, n) cin >> A[i];

    map<int, int> M;
    SparseTable<int> st(A);
    for (int i = 0; i < n - 1; ++i) {
        ++M[st.rmq(i + 1, n + 1) - A[i]];
    }

    auto itr = M.end();
    --itr;
    cout << itr-> second << endl;

    return 0;
}

Measured memory_bytes: 15612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
     }
     if(!(n == 1)) mp[n]++;
}
int main(){
    ll a, b;
    cin >> a >> b;
    ll tmp = gcd(a, b);
    map<ll, ll> mp;
    factorization(tmp, mp);
    ll res = 1;
    for(auto i:mp){
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3620
import numpy as np
import fractions
N = int(input())
a = [int(input()) for i in range(N)]
res = 0
flg = 0
for i in range(N):
    if flg == 1 and a[i] >= 1:
        res += 1
        flg = 0
        a[i] -= 1
    if flg == 1:
        flg = 0
    res += a[i]//2
    a[i] -= (a[i]//2)*2
    if a[i] == 1:
        flg = 1
print(res)


Measured memory_bytes: 17688
fn main() {
    proconio::input! {
        n: usize,
        a: [i32;n],
    }
    let mut b=a.clone();
    b.sort();
    let v1=b[n-1];
    let v2=b[n-2];
    for a in a {
        println!("{}",if a==v1 {v2} else {v1});
    }
}

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long n,count=0;cin>>n;
    string s[n];
    for(long i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(long i=0;i<n;i++){
        if(s[i]!=s[i+1]){
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 9904
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int max = sc.nextInt();
        for (int i=0; i<N-1; i++) {
            int next = sc.nextInt();
            if (next > max) {
                max = next-1;
            } if (next < max) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 49724
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

ll N, D, A, ans, temp;
vector<pair<ll, ll>> mons; // (Xi, Hi)
queue<pair<ll, ll>> q; // (Xi+D, A*cnt)

int main() {
    cin >> N >> D >> A;
    for(int i=0; i<N; i++){
        ll x,h;
        cin >> x >> h;
        mons.push_back(make_pair(x,h));
    }
    sort(mons.begin(), mons.end());
    
    for(int i=0; i<N; i++){
        while(q.size()>0){
            if(q.front().first>=mons[i].first){
                break;
            }
            temp -= q.front().second;
            q.pop();
        }
        ll r = mons[i].second - temp;
        ll cnt = max((ll)0, ((r + A - 1) / A));
        ans += cnt;
        temp += A * cnt;
        q.push(make_pair(mons[i].first + 2 * D, A * cnt));
    }

    cout << ans << endl;
}

Measured memory_bytes: 7532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int backwords[1000100];

int main(void){
    int xy[4];
    int j = 0;
    for (int i = 0; i < 4; i++){
        scanf("%d", &xy[i]);
    }
    for (int i = 0; i < xy[3]-xy[1]; i++){
        printf("U");
        backwords[j] = 'U'; 
        j++;
    }
    for (int i = 0; i < xy[2]-xy[0]; i++){
        printf("R");
        backwords[j] = 'R';
        j++;
    }
    for (int i = 0; i < j; i++){
        if (backwords[i] == 'U'){
            printf("D");
        }
        if (backwords[i] == 'R'){
            printf("L");
        }
    }
    printf("L");
    for (int i = 0; i < xy[3]-xy[1]; i++){
        printf("U");
    }
    printf("UR");
    for (int i = 0; i < xy[2]-xy[0]; i++){
        printf("R");
    }
    printf("D");
    printf("R");
    for (int i = 0; i < xy[3]-xy[1]; i++){
        printf("D");
    }
    printf("DL");
    for (int i = 0; i < xy[2]-xy[0]; i++){
        printf("L");
    }
    printf("U\n");



    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll a[1005],x;
int main()
{
	cin>>x;
	rep(i,1000) a[i]=i*i*i*i*i;
	rep(i,1000) rep2(j,i,1000)
	{
		if(a[i]+a[j]==x) re(i<<" "<<-j)
		if(a[j]-a[i]==x) re(j<<" "<<i)
	}
	return 0;}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10,9)+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
 //cout << setprecision(15) << std::fixed;


int main() {
    int n;
    cin >> n;
    vecst A;
    map<string, int> m;
    for (int i = 0;i < n;i++) {
        string s;
        cin >> s;
        if (m[s] == 0) {
            A.push_back(s);
        }
        m[s]++;
    }
    int ma = 0;
    vecst ans;
    for (int i = 0;i < A.size();i++) {
        if (m[A[i]] == ma) {
            ans.push_back(A[i]);
        }
        else if (m[A[i]] > ma) {
            ma = m[A[i]];
            ans.resize(0);
            ans.push_back(A[i]);
        }
    }
    sort(all(ans));
    for (int i = 0;i < ans.size();i++) {
        print(ans[i]);
    }
} 




Measured memory_bytes: 28400
import java.util.Scanner;

//Path on a Grid
public class Main{

	void run(){
		int[][] move = {{-1,0},{0,1},{1,0},{0,-1}};
		char[] ch = {'U','R','D','L'};
		Scanner sc = new Scanner(System.in);
		boolean[][] e = new boolean[25][25];
		int h = 0, t = 0;
		for(int x=0;x<9;x++){
			char[] s = sc.next().toCharArray();
			for(int j=0;j<s.length;j++){
				if(s[j]=='0')continue;
				if(t==0)e[h*5+j][h*5+j+1] = e[h*5+j+1][h*5+j] = true;
				else e[h*5+j][(h+1)*5+j] = e[(h+1)*5+j][h*5+j] = true;
			}
			if(t==1)h++;
			t=(t+1)%2;
		}
		int i=0, j=0, d=1;
		StringBuilder sb = new StringBuilder();
		boolean con = true;
		while(con){
			for(int k=3;k<=6;k++){
				int nd = (d+k)%4;
				int ni = i+move[nd][0];
				int nj = j+move[nd][1];
				if(0<=ni&&ni<5&&0<=nj&&nj<5&&e[i*5+j][ni*5+nj]){
					sb.append(ch[nd]);
					i = ni; j = nj; d = nd;
					if(i==0&&j==0)con = false;
					break;
				}
			}
		}
		System.out.println(sb);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	int n; cin >> n;
	vector<int> t(n+1);
	vector<int> x(n+1);
	vector<int> y(n+1);
	bool can = true;

	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	for (int i = 1; i < n + 1; i++)
	{
		cin >> t[i] >> x[i] >> y[i];
	}

	for (int i = 1; i < n + 1; i++)
	{
		int dt = t[i] - t[i - 1];
		int dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		if (dt < dist) can = false;
		if (dist % 2 != dt % 2) can = false;
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

const int mod = 1e9 + 7;

// binary exponentiation O(log n)
ll mod_pow(int x, int y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1) res = res * x % mod;  // if right-most bit is 1
    x = x * x % mod;
    y >>= 1;  // right shift y by 1 bit
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  map<int, int> diffs;
  rep(i, n) {
    int pos;
    cin >> pos;
    diffs[pos]++;
  }

  for (int i = (n%2==0); i < n; i++) {
    if (i == 0) {
      if (diffs[i] > 1) {
        cout << 0 << endl;
        return 0;
      }
    }
    else if (diffs[i] > 2) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n/2) {
    ans = (ans * 2) % mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8172
def func arr
    new_arr = []
    prev = arr[0]
    arr[1..-1].each{|v|
        distance = (prev[0] - v[0]) ** 2 + (prev[1] - v[1]) ** 2
        direction = nil
        if prev[0] == v[0]
            direction = prev[1] < v[1] ? "y+" : "y-"
        else
            direction = prev[0] < v[0] ? "x+" : "x-"
        end
        new_arr << [distance, direction]
        prev = v
    }
    new_arr2 = [new_arr[0][0]]
    prev = new_arr[0]
    new_arr[1..-1].each{|v|
        direction = nil
        case prev[1]
        when "y+" then direction = v[1] == "x+" ? "r" : "l"
        when "y-" then direction = v[1] == "x-" ? "r" : "l"
        when "x+" then direction = v[1] == "y-" ? "r" : "l"
        when "x-" then direction = v[1] == "y+" ? "r" : "l"
        end
        new_arr2 << direction
        new_arr2 << v[0]
        prev = v
    }
    new_arr2
end

while true
    n = gets.to_i
    break if n == 0

    lines = Array.new(n + 1){[]}
    (n + 1).times{|i|
        m = gets.to_i
        m.times{lines[i] << gets.chomp.split.map(&:to_i)}
    }
    lines2 = lines.map{|arr| func(arr)}
    templates = [lines2[0]]
    templates << lines2[0].reverse.map{|x| x == "r" ? "l" : x == "l" ? "r" : x}
    match = []
    1.upto(n + 1){|i| match << i if templates.any?{|arr| arr == lines2[i]}}
    puts match
    puts "+" * 5
end



Measured memory_bytes: 6864
import Control.Applicative
import Control.Monad
import Data.List
import Data.Int
import Data.Char

main = do
    [n, k] <- (map read) <$> words <$> getLine
    putStrLn $ show $ solve n k

solve :: Int -> Int -> Double
solve n k = sum [prob i k | i <- [1..n]] / (fromIntegral n)

prob :: Int -> Int -> Double
prob 0 _ = 0
prob i k
    | i >= k = 1
    | otherwise = (prob (i*2) k) / 2

Measured memory_bytes: 764
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;

int main(){
  int n,b; cin >>n >>b;
  int cnt=0;
  while(n){
    n/=b; cnt++;
  }
  cout << cnt;
}

Measured memory_bytes: 256
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}


#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, BTreeMap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! print { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! println { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }

    let s = readl!(String).into_bytes();
    let k = readl!(usize);
    let mut dp = vec![vec![vec![None; k+1]; s.len()]; s.len()];
    struct Env<'a> {dp: &'a mut Vec<Vec<Vec<Option<i32>>>>, s: &'a Vec<u8>, }
    fn rec(env: &mut Env, l: isize, r: isize, k: usize) -> i32 {
        // debug!(l); debug!(r); debug!(k);
        if let Some(v) = env.dp[l as usize][r as usize][k] {
            v
        } else if l >= r {
            if l == r {
                1
            } else {
                0
            }
        } else {
            let mut res = 0;
            res = max(rec(env, l+1, r, k), res);
            res = max(rec(env, l, r-1, k), res);
            if env.s[l as usize] == env.s[r as usize] {
                res = max(rec(env, l+1, r-1, k)+2, res);
            } else if k != 0 {
                res = max(rec(env, l+1, r-1, k-1)+2, res);
            }
            env.dp[l as usize][r as usize][k] = Some(res);
            res
        }
    }
    println!("{}", rec(&mut Env{dp: &mut dp, s: &s}, 0, s.len() as isize-1, k));
}


Measured memory_bytes: 235772
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let ctos = String.of_char
let stocl = String.to_list
let cltos = String.of_list

module MyString = struct
  include String

  let map_to_list f s = L.map f (stocl s)
  let mapi_to_list f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let spoc = S.split_on_char
let spsp s = spoc ' ' s

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let (x,y) = rdi2 () in
  let result = x * y in
  puti result
;;


Measured memory_bytes: 5512
import Control.Monad (replicateM)

main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine :: IO [Int]
  ms    <- replicateM n readLn :: IO [Int]
  print $ f n x ms

f :: Int -> Int -> [Int] -> Int
f n x ms = n + g x ms
  where
    g :: Int -> [Int] -> Int
    g x ms =  (x - sum ms) `div` (minimum ms)

Measured memory_bytes: 1020
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

odd = false
min = a[0].abs
sum = 0
for i in 1..n do
    sum += a[i-1].abs
    if min > a[i-1].abs
        min = a[i-1].abs
    end
    if a[i-1] < 0
        odd = !(odd)
    end
end
if odd 
    sum -= 2*min
end
p sum


Measured memory_bytes: 9732
N = int(input())
h = [int(i) for i in input().split()]
dp = []
for i in range(N):
    if i == 0:
        dp.append(0)
        continue
    if i == 1:
        dp.append(abs(h[1] - h[0]))
        continue
    dp.append(min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])))
print(dp[-1])


Measured memory_bytes: 13980
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}


int main(){
  string s; cin >>s;
  int n=s.size();
  
  vector<int> ptr(n,0);   // ptr[itr]=next(itr)
  vector<int> abc(26,0);  // abc[alp]=last(itr)
  vector<int> cnt(26,1);  // cnt[alp]
  set<pair<int,int>> st;  // <cnt,alp>
  rep(i,26){
    ptr.push_back(-1);
    abc[i]=n+i;
    st.insert({1,i});
    char c='a'+i;
    s.push_back(c);
  }

  rep(_i,n){
    int i=n-_i-1;
    int c=s[i]-'a';
    if(df)print(c);
    pair<int,int> p=*st.begin();
    int it=p.first;
    ptr[i]=abc[p.second];
    abc[c]=i;
    p={cnt[c],c};
    st.erase(p);
    p={1+it,c};
    st.insert(p);
    cnt[c]=1+it;
    if(df)print(st);
  }
  if(df)print(ptr);
  int itr=abc[st.begin()->second];
  do{
    //    if(df)print(itr);
    char c=s[itr];
    cout << c;
    itr=ptr[itr];
  }while(itr>0);
  printf("\n");
}


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


int main(){
  long N;
  cin >> N;
  long ans=10;
  for(long i=1; i<=sqrt(N); i++){
    if(N%i==0){
      int keta=max(floor(log10(i))+1,floor(log10(N/i))+1);
      if(keta<ans) ans=keta;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace::std;

int x, a, b;
int A, B;
int main() {
	cin >> x >> a >> b;
	if (x - a < 0) {
		A = a - x;
	}
	else {
		A = x - a;
	}
	if (x - b < 0) {
		B = b - x;
	}
	else {
		B = x - b;
	}

	if (A > B) {
		cout << "B";
	}
	else {
		cout << "A";
	}
	return 0;
		}


	


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc075/tasks/abc075_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N, M, a, b, cnt;
unordered_map<int, set<int>> g;
vector<pair<int, int>> s;

void check(int n, pair<int, int> &p, set<int> &v)
{
  for (auto &d : g[n])
  {
    if (p.first == min(n, d) && p.second == max(n, d))
      continue;

    auto r = v.insert(d);
    if (r.second)
      check(d, p, v);
  }
  return;
}

int main()
{
  cin >> N >> M;
  FOR(i, 1, N + 1)
  {
    g[i] = {};
  }
  REP(i, M)
  {
    cin >> a >> b;
    if (b < a)
      swap(a, b);
    s.push_back(make_pair(a, b));
    g[a].insert(b);
    g[b].insert(a);
  }

  cnt = 0;
  for (auto &ss : s)
  {
    set<int> v = {1};
    check(1, ss, v);
    if (v.size() < N)
      cnt++;
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 256
import qualified Data.Set as ST
import Control.Monad

main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    xs <- ST.fromList . concat <$> (replicateM k $ getLine >> getLine >>= return . map read . words) :: IO (ST.Set Int)
    print $ n - ST.size xs

Measured memory_bytes: 6660