akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

long long mypow(long long k, long long n) {
	long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}


int main() {
	int N; cin >> N;
	vector<ll> x(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> x[i];
	}

	vector<ll> f(N + 1), invf(N + 1);
	f[0] = 1, invf[0] = 1;
	for (int i = 1; i <= N; i++) {
		f[i] = f[i - 1] * i;
		f[i] %= DIV;
		invf[i] = mypow(f[i], DIV - 2);
	}

	vector<ll> tot(N + 1);
	tot[1] = f[N - 1];
	for (int i = 2; i <= N-1; i++) {
		tot[i] = tot[i - 1] + f[N - 1] * mypow(i, DIV - 2);
		tot[i] %= DIV;
		//printf("tot[%d]=%lld\n", i, tot[i]);
	}

	ll ans = 0;
	for (int i = 2; i <= N; i++) {
		ans += ((x[i] - x[i - 1]) * tot[i - 1]) % DIV;
		ans %= DIV;

	}
	cout << ans << endl;
}

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

int main() {
  char S[10];
  scanf("%s",S);
  int len = strlen(S);
  int l=S[0]-'0',m=S[1]-'0',n=S[2]-'0';
  int min=abs((100*l+10*m+n)-753);
  for (int i = 1; i < len-2; i++) {
    int a=S[i]-'0',b=S[i+1]-'0',c=S[i+2]-'0';
    int dif=abs((100*a+10*b+c)-753);
    if (min > dif) min = dif;
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b){if (a > b) a = b;}
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b){if (a < b) a = b;}
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

int dp[110][110];
char s[110][110];


int main()
{
	int H, W;
	cin >> H >> W;

	rep(i, H) {
		rep(j, W) {
			cin >> s[i][j];
		}
	}

	//大きな数で初期化
	rep(i, H+1) {
		rep(j, W+1) {
			dp[i][j] = (1 << 25);
		}
	}

	//初期条件
	if (s[0][0] == '#') dp[0][0] = 1;
	else dp[0][0] = 0;

	rep(i, H) {
		rep(j, W) {
			if (s[i][j] == '#') {
				if (s[i][j + 1] == '#') chmin(dp[i][j+1], dp[i][j]);
				else chmin(dp[i][j + 1], dp[i][j]);
			}
			else {
				if (s[i][j + 1] == '#') chmin(dp[i][j + 1], dp[i][j] + 1);
				else chmin(dp[i][j + 1], dp[i][j]);
			}

			if (s[i][j] == '#') {
				if (s[i + 1][j] == '#') chmin(dp[i + 1][j], dp[i][j]);
				else chmin(dp[i + 1][j], dp[i][j]);
			}
			else {
				if (s[i + 1][j] == '#') chmin(dp[i + 1][j], dp[i][j] + 1);
				else chmin(dp[i + 1][j], dp[i][j]);
			}

		}
	}
	
	/*rep(i, H) {
		rep(j, W) {
			cout  << dp[i][j] << " ";
		}
		cout << endl;
	}*/

	cout << dp[H-1][W-1] << endl;
	
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t;
	s+=t;
	stringstream ss; ss<<s;
	int x; ss>>x;
	for (int i=0; i<1000; i++)
		if(x==i*i) {
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
	return 0;
}


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

long long int n, a, b;
vector<long long int> v;

bool check(long long int m){
    long long int sum = 0;
    for(int i=0;i<n;++i){
        if(v[i] > m*b)sum += (v[i] - m*b + (a-b-1)) / (a-b);
    }

    return sum <= m;
}

int main(){
    cin >> n >> a >> b;
    for(int i=0;i<n;++i){
        long long int h;
        cin >> h;
        v.push_back(h);
    }

    long long int ng = 0, ok = 1000000000;
    while(abs(ok-ng) > 1){
        long long int mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
import java.io.IOException;
class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long a = scan.nextLong();
    for(int i=0;i<n-1;i++){
      long x = scan.nextLong();
       a = (a / gcd(a,x)) * x;
    }
    System.out.println(a);
  }
  static long gcd(long a , long b){
    if(a ==0) return -1;
    if(a < b) {
      long x = a;
      a = b;
      b = x;
    }
     return (b == 0 || a%b == 0) ? b : gcd(b,a%b);
  }
}


Measured memory_bytes: 23636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  long long ans = 1LL << 60;
  for (int j = -1000; j <= 1000; j++) {
    long long cost = 0;
    for (int i = 0; i < n; i++) {
      cost += 1LL * (x[i] - j) * (x[i] - j);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{	
 int a, b;
 char op;
 scanf("%d %c %d", &a, &op, &b);
 while (op != '?') 
  {
    if (op == '+')
     printf("%d\n",a+b);
    else if (op == '-')
     printf("%d\n",a-b);
    else if (op == '*')
     printf("%d\n",a*b);
    else if(op=='/')
     printf("%d\n",a/b);
    scanf("%d %c %d", &a, &op, &b);
  }
 return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;


LLI power(LLI n, LLI p, LLI m){
  LLI ret = 1;
  while(p>0){
    if(p&1) (ret *= n) %= m;
    (n *= n) %= m;
    p /= 2;
  }
  return ret;
}

LLI mod_inv(LLI n, LLI p){return power(n,p-2,p);}

template <LLI mod> class Combination{
public:
  vector<LLI> facto = {1};
  vector<LLI> ifacto = {1};

  LLI factorial(LLI i){
    if(i < 0) throw exception();
    if(facto.size() <= i) facto.resize(i+1, -1);
    if(i == 0) return facto[0] = 1;
    LLI j = i;
    for(;j>=0;--j) if(facto[j] != -1) break;
    for(LLI k=j+1; k<=i; ++k) (facto[k] = facto[k-1] * k) %= mod;
    return facto[i];
  }

  LLI factorial_inverse(LLI i){
    if(i < 0) throw exception();
    if(ifacto.size() <= i) ifacto.resize(i+1, -1);
    if(ifacto[i] != -1) return ifacto[i];
    return ifacto[i] = mod_inv(factorial(i), mod);
  }

  LLI P(LLI n, LLI k){
    if(n < k or n < 0 or k < 0) return 0;
    return (factorial(n) * factorial_inverse(n-k)) % mod;
  }

  LLI C(LLI n, LLI k){
    if(n < k or n < 0 or k < 0) return 0;
    return (P(n,k) * factorial_inverse(k)) % mod;
  }

  LLI H(LLI n, LLI k){
    return C(n+k-1, k);
  }
};



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

  Combination<mod> com;

  string L;
  while(cin >> L){
    int N = L.size();

    LLI ans = 0;

    int count_1 = count(ALL(L), '1');

    (ans += power(2, count_1, mod)) %= mod;
    

    int c = 0;
    REP(i,N){
      if(L[i] == '1'){

	LLI x = power(2, c, mod);
	LLI y = power(3, N-i-1, mod);

	(ans += x*y%mod) %= mod;
	
	++c;
      }
    }


    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 512
h,w = map(int,input().split())

f = []
for i in range(h):
    s = list(map(lambda x:0 if x== "." else 1,list(input())))
    f.append(s)

from collections import deque
def dfs_field(field,st,go):
    """
    :param field: #が1,.が0になったfield
    st: [i,j]
    go: [i,j]
    :return: 色々今は回数returnしている。
    """
    h = len(field)
    w = len(field[0])
    around = [[-1,0],[1,0],[0,1],[0,-1]]
    que = deque()
    visited = set()
    visited.add(str(st[0])+","+str(st[1]))
    que.append([st[0],st[1],0])
    max_cos = 0
    while True:
        if len(que) == 0:
            return  max_cos
        top = que.popleft()
        nowi = top[0]
        nowj = top[1]
        cost = top[2]
        for a in around:
            ni = nowi+a[0]
            nj = nowj+a[1]
            if ni < 0 or ni > h-1 or nj < 0 or nj > w-1:
                continue
            if field[ni][nj] == 1:
                continue
            if ni == go[0] and nj == go[1]:
                return cost+1
            else:
                key = str(ni)+","+str(nj)
                if key not in visited:
                    que.append([ni,nj,cost+1])
                    visited.add(key)
                    if cost+1 > max_cos:
                        max_cos = cost+1
        # print(que)



ans = 0
for i in range(h):
    for j in range(w):
        if f[i][j] == 0:
            ct = dfs_field(f,[i,j],[-2,-2])
            if ans < ct:
                ans = ct

print(ans)



Measured memory_bytes: 45020
n = int(input())
a = list(map(int, input().split())) # 横入力

x = [0]
aaa = 0
for i in range(n):
    aaa += a[i]
    x.append(aaa)
aa = sum(a)
y = [aa]
for i in range(n):
    aa -= a[i]
    y.append(aa)

ans = 202020202020
for i in range(n+1):
    ans = min(ans, abs(x[i] - y[i]))

print(ans)

Measured memory_bytes: 29964
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return

template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int)2e5+123

int n,a,b;

void solve(){
    int soma = 0;
	cin >> n;
    cin >> a >> b;
    for(int i = a; i <=b;i++){
    	if(i%n==0){
    		cout << "OK" << endl;
    		return;
		}
	}
	cout << "NG" << endl;
    
}
int main(){_

        solve();
    	
}

Measured memory_bytes: 3640
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    for i in range(n):
        A.append(A[i] - 1)
        A.append(A[i] + 1)

    D = Counter(A)
    res = 0
    for v in D.values():
        res = max(res, v)

    print(res)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26080
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

int const MAXL = 1e5;

int msb_(int x) { return 31 - __builtin_clz(x); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> V(N), W(N);
  for(int i = 0; i < N; ++i) std::cin >> V[i] >> W[i];
  int pN = std::min(N+1, 1024);
  auto dp = mk2d(pN, MAXL+1, (int)0);
  for(int i = 1; i < pN; ++i) {
    int pi = i/2;
    // don't use V[i-1], W[i-1]
    std::copy_n(dp[pi].begin(), MAXL+1, dp[i].begin());
    // use V[i-1], W[i-1];
    for(int w = MAXL; w >= W[i-1]; --w) {
      int nv = dp[pi][w-W[i-1]] + V[i-1];
      if(nv > dp[i][w]) dp[i][w] = nv;
    }
  }
  int sumv[256], sumw[256];
  sumv[0] = sumw[0] = 0;
  int Q; std::cin >> Q;
  for(int q = 0; q < Q; ++q) {
    int u, L; std::cin >> u >> L;
    if(u < pN) {
      std::cout << dp[u][L] << "\n";
      continue;
    }
    std::vector<int> nodes;
    while(u >= pN) {
      nodes.push_back(u);
      u /= 2;
    }
    int ans = dp[u][L];
    int S = (1<<nodes.size());
    for(int s = 1; s < S; ++s) {
      int m = msb_(s);
      sumv[s] = sumv[s^(1<<m)] + V[nodes[m]-1];
      sumw[s] = sumw[s^(1<<m)] + W[nodes[m]-1];
      if(sumw[s] > L) continue;
      ans = std::max(ans, sumv[s] + dp[u][L - sumw[s]]);
    }
    std::cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 407120
input_num = int(input())

combinations = [(row1, row2, row3, row4, row5, row6)
               for row1 in range(0, 6)
               for row2 in range(0, 6)
               for row3 in range(0, 6)
               for row4 in range(0, 6)
               for row5 in range(0, 6)
               for row6 in range(0, 6)]


num_list = []

for i in combinations:
  row1, row2, row3, row4, row5, row6 = i
  draw = 6 ** 1 * row1 ++ 6 ** 2 * row2 + 6 ** 3 * row3 + 6 ** 4 * row4 + 6 ** 5 * row5 + 6 ** 6 * row6
  if draw > input_num:
    continue
  else:
    result = input_num - draw
    draw_list = sum(i)
    for n in reversed(range(1, 6)):
      draw_n = result // 9 ** n
      result -= 9 ** n * draw_n
      draw_list += draw_n
    draw_list += result
    num_list.append(draw_list)
    
print(str(min(num_list)))

Measured memory_bytes: 8088
#include <stdio.h>
 
int main(){
   int a, b, c, i, y=0;

   scanf("%d %d %d", &a, &b, &c);

   for(i=a; i<=b; i++){
      if(c%i==0){
         y = y + 1;
      }
   }

   printf("%d\n", y);

   return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int w,a,b;
	cin >> w >> a >> b;
	int ans = 0;
	if (a < b){
		if (a + w < b){
			ans = b - (a + w);
		}
	}
	else{
		if (b + w < a){
			ans = a - (b + w);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused)]
use std::cmp::{max, min};

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

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

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

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

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

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

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

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

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        l: u64,
        r: u64,
    }

    let mut tmp = 2018;
    for x in l..r {
        for y in x + 1..r + 1 {
            tmp = std::cmp::min(tmp, (x * y) % 2019);
            if tmp == 0 {
                println!("{}", tmp);
                return;
            }
        }
    }

    println!("{}", tmp);
}

Measured memory_bytes: 4352
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#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;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;

void input(){
    int n;
    cin >> n;
    vector<int>a(n);
    f(i, n)cin >> a[i];
    string ans = "APPROVED";
    f(i, n){
        if(a[i] %2 == 0){
            if(a[i] % 3 == 0 || a[i] % 5 == 0){
                int x= 1;
            }else{
                ans = "DENIED";
            }
        }
    }
    cout << ans << endl;
}
int main(){
    input();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

VI prime;
void generate_prime() {
    prime.push_back(2); 
    FOR(i, 3, 55555) {
        for(auto p : prime) {
            if(i % p == 0) break;
            if(p > sqrt(i)) {
                prime.push_back(i);
                break;
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    generate_prime();
    VI ans;
    for(auto p : prime)if(p % 5 == 1) ans.push_back(p);
    REP(i, n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

}



Measured memory_bytes: 38028
#include <iostream>
#include <algorithm>

using namespace std;


int main() {
	
	int w[10], k[10];

	for (int i = 0; i < 10; i++)
		cin >> w[i];

	for (int i = 0; i < 10; i++)
		cin >> k[i];

	sort(w, w + 10);
	sort(k, k + 10);
	cout << w[7] + w[8] + w[9] << " "
		<< k[7] + k[8] + k[9] << "\n";
	return 0;

}


Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std; 

const int NIL = -1;

void maxHeapify(vector<int>& A, int i, int H)
{
	int l = 2 * i, r = 2 * i + 1, largest;
	if (l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if (r <= H && A[r] > A[largest])
		largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(A, largest, H);
	}
}

void buildMaxHeap(vector<int>& A, int H)
{
	for (int i = H / 2; i >= 1; i--)
		maxHeapify(A, i, H);
}

int main(void)
{
	int H, key;
	vector<int> heap;
	heap.push_back(NIL);
	cin >> H;
	for (int i = 0; i < H; i++) {
		cin >> key;
		heap.push_back(key);
	}
	buildMaxHeap(heap, H);
	for (int i = 1; i <= H; i++) {
		cout << " " << heap[i];
	}
	cout << endl;
	return 0;
}




Measured memory_bytes: 4888
#include <stdio.h>
#include <math.h>
#define N 100   // n?¬????????????????????????§?¬??????°

int main(void) {
    int n, i;
    double x[N], y[N], D1, D2, D3, Du;
    D1 = 0.0; D2 = 0.0; D3 = 0.0; Du = 0.0;

    scanf("%d", &n);   // n?¬???????????????????
    for (i = 0; i < n; i++) scanf("%lf", &x[i]);    // x????????????????????????????????????
    for (i = 0; i < n; i++) scanf("%lf", &y[i]);    // y????????????????????????????????????
    for (i = 0; i < n; i++) D1 += fabs(x[i] - y[i]);
    printf("%f\n", D1);
    for (i = 0; i < n; i++) D2 += fabs(pow(x[i] - y[i], 2)); D2 = sqrt(D2);
    printf("%f\n", D2);
    for (i = 0; i < n; i++) D3 += fabs(pow(x[i] - y[i], 3)); D3 = cbrt(D3);
    printf("%f\n", D3);
    for (i = 0; i < n; i++) if (fabs(x[i] - y[i]) > Du) Du = fabs(x[i] - y[i]);
    printf("%f\n", Du);

    return 0;
}

Measured memory_bytes: 728
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
	private: int _num[32],_head;
	public: int SUF; template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'),putchar(SUF);return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; putchar(SUF); return *this;}
	fastout() {_head=0,SUF=' ';}
}fout;
// ----------------------------
#define int ll
// using namespace std;
const int maxn=3004;
const int mod=998244353,inf=1000000007;

int n,s;
int a[maxn];
ll f1[maxn][maxn],f2[maxn][maxn],ans;

signed main()
{
	fin>>n>>s;
	for(rgi i=1;i<=n;++i) fin>>a[i];
	for(rgi i=1;i<=n;++i)
	{
		for(rgi j=0;j<=s;++j)
		{
			f2[i][j]=f2[i-1][j];
			if(j>=a[i])
			{
				int t=j-a[i];
				f1[i][j]=f2[i-1][t];
				if(!t) (f1[i][j]+=i)%=mod;
			}
			(f2[i][j]+=f1[i][j])%=mod;
		}
		(ans+=f1[i][s]*(n-i+1))%=mod;
	}
	fout.SUF='\n',fout<<ans;
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 141184
main :: IO () 
main = do
    text <- getLine
    let reversed = reverse text
    if execDreamer' reversed
        then putStrLn "YES"
        else putStrLn "NO"

execDreamer' :: String -> Bool
execDreamer' "" = True
execDreamer' ('m':'a':'e':'r':'d':xs) = execDreamer' xs
execDreamer' ('r':'e':'m':'a':'e':'r':'d':xs) = execDreamer' xs
execDreamer' ('e':'s':'a':'r':'e':xs) = execDreamer' xs
execDreamer' ('r':'e':'s':'a':'r':'e':xs) = execDreamer' xs
execDreamer' _ = False

Measured memory_bytes: 7548
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    if(n == 1) {
        println(n)
        return
    }
    val cnt = mutableMapOf<Int,Int>()
    for(i in (2..n)) {
        val ret = primeDivide(i)
        for(j in ret) {
            if(cnt.containsKey(j.key)) {
                cnt[j.key] = cnt[j.key]!! + j.value
            } else {
                cnt[j.key] = j.value
            }
        }
    }
    var ans = 1L
    for(i in cnt.values) {
        ans *= i+1
        ans %= (1000000000 + 7)
    }
    println(ans)
}

val dic = mutableMapOf<Int,MutableMap<Int,Int>>()
fun primeDivide(n:Int):Map<Int,Int>{
    dic[n]?.let { return it }

    for(i in (2 until n)) {
        if(n%i != 0) {
            continue
        }
        val tm = dic[n/i]
        tm?.let {
            val ret = mutableMapOf<Int,Int>()
            for(j in it) {
                ret[j.key] = j.value
            }
            if(ret.containsKey(i)) {
                ret[i] = ret[i]!!+1
            } else {
                ret[i] = 1
            }
            dic[n] = ret
            return ret
        }
    }
    val tmp = mutableMapOf(n to 1)
    dic[n] = tmp
    return tmp
}


Measured memory_bytes: 33908
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define setp(x) setprecision(x)
using ll = long long;

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

	string S = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

	rep(i, 0, s.size()) {
		s[i] = S[s[i] - 'A' + n];
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut ans = 0;
    for i in 1..n + 1 {
        ans += i - 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
using namespace std;
using ll=long long;
using vi=vector<int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  int N, K; cin>>N>>K;
  vi h(N); REP(i,N) cin>>h[i];

  vi dp(N+K); REP(i,N+K) dp[i]=INF;
  dp[0] = 0;

  int minNext;
  int nextIndex;
  int newValue;
  FOR(i,0,N){
    FOR(j,1,K+1){
      newValue = dp[i]+abs(h[i]-h[i+j]);
      dp[i+j] = min(dp[i+j], newValue);
    }
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[2] = {0, 1};
ll dy[2] = {1, 0};

int main(void){
    ll h, w;
    cin >> h >> w;
    string s[h];
    for(ll i = 0; i < h; i++)
        cin >> s[i];
    ll count = 0;
    bool ans = true;
    for(ll i = 0; i < h; i++){
        ll check = 0;
        for(ll j = 0; j < w; j++){
            if(s[i][j]=='#') {
                count++;
                check++;
            }
        }
        if(check == 0)
            ans = false;
    }
    if(count!=h+w-1) ans = false;
    if(ans==true)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    l=1
    from collections import defaultdict
    dp=dict()
    ndp=defaultdict
    for i in range(K):
        ndp=dict()
        l=N
        s=0
        while l>0:
            d=N//l
            r=N//(d+1)
            if i==0:
                s=1
            else:
                s+=dp[d]
            ndp[l]=(l-r)*s%mod
            l=r
        dp=ndp
    ans=0
    for v in dp.values():
        ans=ans+v
        ans%=mod 
    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 249848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 12345;
map<ll,ll>dp;
ll w[maxn],v[maxn];
ll n,W;
int main()
{
    scanf("%lld %lld",&n,&W);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld%lld",&w[i],&v[i]);
    }
    if(w[1]<=1e3)
    {
        ll ans=min(W,(w[1]+3)*n);
        for(ll i=1; i<=n; i++)
        {
            for(ll j=ans; j>=1; j--)
            {
                if(j>=w[i])
                    dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
            }
        }
        cout<<dp[ans]<<endl;
    }
    else
    {
        ll ans=min(W,(w[1]+3)*n);
        for(ll i=1; i<=n; i++)
        {
            for(ll j=ans; j>=w[1]; j-=w[1])
            {
                if(j>=w[i])
                    dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
            }
        }
        cout<<dp[ans]<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// 文字列の入力
		//String s1 = sc.next();

		int a=0;
		int b=0;
		for(int i=0;a<=n;i++){
			b = a;
			a = (int)Math.pow(i, 2);
		}

		// 出力
		System.out.println(b);
	}
}


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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	int ans = 0;
	int now = 1;
	if (now < b) { now = a; ans++; }
	while (now < b) {
		now += a-1;
		ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 123456;
int visit[3][MAXN];
int dis[3][MAXN];
vector<int> G[MAXN];

struct Node {
    int x, d, st;
    Node(int _x, int _d, int _st) : x(_x), d(_d), st(_st) {}
    bool operator < (const Node &a) const {
        return d > a.d;
    }
};

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        G[u].push_back(v);
    }
    int S, T;
    scanf("%d %d", &S, &T);
    priority_queue<Node> pq;
    pq.push(Node(S, 0, 0));
    while (!pq.empty()) {
        auto tp = pq.top();
        pq.pop();
        int x = tp.x, d = tp.d, st = tp.st;
        if (visit[st][x]) continue;
        visit[st][x] = 1;
        dis[st][x] = d;
        for (auto v : G[x]) {
            int offs = 0;
            if (st == 0) offs = 1;
            pq.push(Node(v, d + offs, (st + 1) % 3));
        }
    }
    printf("%d\n", dis[0][T] ? dis[0][T] : -1);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


Measured memory_bytes: 12052
s = input()
t = input()
S = len(s)
T = len(t)
dp = [[0 for _ in range(T+1)] for _ in range(S+1)]
for i in range(S):
    for j in range(T):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1])
ans = ''
i = S
j = T
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)

Measured memory_bytes: 120412
#include "bits/stdc++.h"
using namespace std;
const int maxsum = 2000 * 1000;
bitset <maxsum + 10> dp;

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		dp |= dp << x;
		sum += x;
	}
	sum = (sum + 1) >> 1;
	for(int i = 1; i <= maxsum; i++) {
		if(sum <= i && dp[i] == 1) {
			printf("%d\n", i);
			exit(0);
		}
	}	
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  ll a[200000];
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a[i];
    if(i) a[i]+=a[i-1];
  }
  ll ans;
  for(int i=0;i<N-1;i++){
    ll x=a[i],y=a[N-1]-a[i];
    if(i==0) ans=abs(x-y);
    else ans=min(ans,abs(x-y));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class SuffixArray(object):
    def __init__(self,s):
        self.__s=s
        self.__n=len(s)
        self.__suffix_array()
        self.__lcp_array()
        self.__sparse_table()

    def __suffix_array(self):
        s=self.__s; n=self.__n
        sa=list(range(n))
        rank=[ord(s[i]) for i in range(n)]
        tmp=[0]*n
        k=1
        cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
        while(k<=n):
            sa.sort(key=cmp_key)
            tmp[sa[0]]=0
            for i in range(1,n):
                tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
            rank=tmp[:]
            k<<=1
        self.__sa=sa
        self.__rank=rank

    def __lcp_array(self):
        s=self.__s; n=self.__n
        sa=self.__sa; rank=self.__rank
        lcp=[0]*n
        h=0
        for i in range(n):
            j=sa[rank[i]-1]
            if(h>0): h-=1
            if(rank[i]==0): continue
            while(j+h<n and i+h<n and s[j+h]==s[i+h]): h+=1
            lcp[rank[i]]=h
        self.__lcp=lcp

    def __sparse_table(self):
        n=self.__n
        logn=max(0,(n-1).bit_length())
        table=[[0]*n for _ in range(logn)]
        table[0]=self.__lcp[:]
        from itertools import product
        for i,k in product(range(1,logn),range(n)):
            if(k+(1<<(i-1))>=n): table[i][k]=table[i-1][k]
            else: table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
        self.__table=table

    @property
    def suffix(self):
        return self.__sa

    def lcp(self,a,b):
        if(a==b): return self.__n-a
        l,r=self.__rank[a],self.__rank[b]
        l,r=min(l,r)+1,max(l,r)+1
        i=max(0,(r-l-1).bit_length()-1)
        table=self.__table
        return min(table[i][l],table[i][r-(1<<i)])

def resolve():
    S=input()
    n=len(S)
    k=int(input())

    if(n==1):
        print(S)
        return

    sa=SuffixArray(S)
    D=set()
    for i in sa.suffix:
        for j in range(i+1,n+1):
            D.add(S[i:j])
            if(len(D)==k):
                print(sorted(D)[-1])
                return
resolve()

Measured memory_bytes: 45552
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	bool flg;
	ll n, k,tmp;
	vll ans(6, 0);
	in(n);

	in(k);

	sll l{ 0,1,2,3,4,5,6,7,8,9 };
	vll d(k);
	rep(i, 0, k) {
		in(d[i]);
		l.erase(d[i]);
	}


	ll i = 0;
	while(n>0){
		tmp = n % 10;
		n /= 10;

		if (l.find(tmp) == l.end()) {
			flg = true;
			for (auto itr = l.begin(); itr != l.end(); itr++) {
				if (*itr > tmp) {
					ans[i] = *itr;

					for (ll j = i - 1; j >= 0; j--) {
						ans[j] = *l.begin();
					}
					flg = false;
					break;
				}
			}
			if (flg) {
				n++;
				ans[i]= *l.begin();
				for (ll j = i - 1; j >= 0; j--) {
					ans[j] = *l.begin();
				}
			}
		}
		else {
			ans[i] = tmp;
		}
		i++;
	}

	flg = false;
	for (ll i = 5; i >= 0; i--) {
		if (ans[i] != 0) {
			flg = true;
		}
		if (flg) {
			out(ans[i]);
		}
	}
	outn("");

	return 0;

	}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

// Segment Tree : 時間計算量 O(n log n), 空間計算量 O(n)
// require  : なし
// verified : 
//
// T はモノイド（単位元を持ち，結合則が成り立つ）であることが要求される
template <class T, class U = size_t>
struct SegTree {
	// !!! 実装時 t(lhs, rhs) の引数の順番に注意(意図せず可換則が要求されてしまう) !!!
	typedef typename T::V V;
	explicit SegTree(U _n = 0, const T &t = T()) : n(1), t(t) {
		while (n < _n) n *= 2;
		v.assign(n * 2 - 1, t.identity());
		if (n >= 2) {
			for (U i = n - 2;; --i) {
				v[i] = t(v[i * 2 + 1], v[i * 2 + 2]);
				if (i == 0) break; // Uが符号無し整数の可能性がある為こう実装している
			}
		}
	}
	V operator[](U i) const { return v[n - 1 + i]; }
	void set(U i, const V & x) {
		i += n - 1;
		v[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			v[i] = t(v[i * 2 + 1], v[i * 2 + 2]);
		}
	}
	// [a,b)の範囲についてのクエリを返す
	V get(U a, U b) const { return q(a, b, 0, 0, n); }
private:
	// t : traits のインスタンス
	// v : 完全二分木の配列表現
	// n : 完全二分木の葉の数
	T t;
	vector<V> v;
	U n;

	// [a,b)の範囲についてのクエリを返す
	// k     : 現在見ている接点の番号
	// [l,r) : kに対応した範囲 
	V q(U a, U b, U k, U l, U r) const {
		if (r <= a || b <= l) return t.identity(); // 範囲外
		if (a <= l && r <= b) return v[k];         // [l,r) ⊂ [a,b)

												   //[l,r)の一部が[a,b)に含まれる
		U c = (l + r) / 2;
		return t(
			q(a, b, k * 2 + 1, l, c),
			q(a, b, k * 2 + 2, c, r)
		);
	}
};
template <class T>
struct MinTrait {
	typedef T V;
	V identity() const { return TEN(10); }
	V operator()(const V &a, const V &b) const { return min(a, b); }
};

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vl a(n); REP(i, n) cin >> a[i], a[i]--;

	vl rev(n); REP(i, n) rev[a[i]] = i;

	SegTree<MinTrait<ll>> st_odd(n), st_even(n);
	REP(i, n) (i % 2 ? st_even : st_odd).set(i, a[i]);

	using P = tuple<ll, ll, ll, ll>;
	using vp = vector<P>;

	priority_queue<P, vp, greater<P>> que;
	auto f = [&](ll b, ll e) {
		if (b == e) return;
		ll i_l = rev[(b % 2 ? st_even : st_odd).get(b, e)];
		ll i_r = rev[(b % 2 ? st_odd : st_even).get(i_l, e)];
		que.push(P(a[i_l], a[i_r], b, e));
	};
	f(0, n);

	vl ans;
	while (!que.empty()) {
		ll lv, rv, b, e;
		tie(lv, rv, b, e) = que.top();
		ans.push_back(lv);
		ans.push_back(rv);
		que.pop();

		ll i_l = rev[lv], i_r = rev[rv];
		f(b, i_l);
		f(i_l + 1, i_r);
		f(i_r + 1, e);
	}
	REP(i, ans.size()) cout << ans[i] + 1 << (i != ans.size() - 1 ? " " : "");

	return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999

//char型のポインタ(=配列と意味は同じ)をString型と定義([0]から数える)
typedef char* String;

//文字列の長さを求める関数
int string_len(String str){
    int len=0;
    while(str[len]!=0){
        len++;
    }
    return len;
}

//文字列を標準入力から読み込み、それをString型のメモリを確保し直してくれる関数
//S[0]~S[n-1]までが入力で、S[n]は0になる
String string_input(void){
    int i,len;
    char buf[100000];
    String str;
    scanf("%s",buf);//buf=入力した文字列が入るchar型の配列
    //ここまでは文字列の長さがわからなかったから、一旦1000個分のメモリを用意しそこに入力させる
    
    len=string_len(buf);//len=文字列の長さを表すint型変数
    NEW(str,len+1);//strはただのポインタだから、ここでNEWを使ってメモリを確保しなくちゃいけない
    for(i=0;i<len;i++){
        str[i]=buf[i];
    }
    str[len]=0;
    
    return str;
}


int main(void){
    String S=string_input();
    int len=string_len(S);

    int ans=0;
    for(int i=0;i<len-1;i++){
        if(S[i]!=S[i+1]){
            ans++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 384
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
  	ll n;
  	cin >> n;
	vector<ll> a(n+1,0);
  	for(ll i=0;i<n-1;i++){
    	ll tmp;
      	cin >> tmp;
      	a[tmp]++;
    }
  	for(ll i=1;i<=n;i++){
    	cout << a[i] << endl;
    }
}

Measured memory_bytes: 4776
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BSumOfThreeIntegers solver = new BSumOfThreeIntegers();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSumOfThreeIntegers {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt(), s = in.nextInt();
            long ans = 0;
            for (int x = Math.max(0, s - 2 * k); x <= Math.min(k, s); x++) {
                ans += Math.max(Math.min(k, s - x) - Math.max(0, s - x - k) + 1, 0);
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 22100
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

class Combination {
public:
    vector <ll> fac, inv, fiv;

    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i % MOD; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
            fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
        }
    }

    ll C(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[k] % MOD * fiv[n - k] % MOD;
    }

    ll P(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[n - k] % MOD;
    }

    ll H(ll n, ll k) {
        if (n == 0 && k == 0) return 1;
        return C(n + k - 1, k - 1);
    }
};

ll binomial(ll N, ll K) {
    if (K < 0 || N < K) return 0;

    Combination com(200005);

    ll ret = 1;
    for (ll i = 1; i <= K; i++) {
        ret *= N--;
        ret %= MOD;

        ret *= com.inv[i];
        ret %= MOD;
    }

    return ret;
}

ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}

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

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = pow_mod(2, n, MOD);
    ans = (ans - 1 + MOD) % MOD;
    ans = (ans - binomial(n, a) + MOD) % MOD;
    ans = (ans - binomial(n, b) + MOD) % MOD;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4992