akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn._
object Main extends App {
  val Array(n, a, b) = readLine.trim.split(' ').map(_.toLong)
  val positions = readLine.trim.split(' ').map(_.toInt)
  var sum = 0L
  for (p ← positions.indices.tail) {
    if ((positions(p) - positions(p - 1)) * a > + b) {
      sum += b
    }else {
      sum += (positions(p) - positions(p - 1)) * a
    }
  }
  println(sum)
}

Measured memory_bytes: 40268
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<int> a(N);
    ll t = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        t += a[i];
    }

    ll s = a[0];
    t -= s;
    ll ans = MAXINF;
    Rep(i, 1, N-1){
        ans = min(ans, abs(s-t));
        s += a[i];
        t -= a[i];
    }
    ans = min(ans, abs(s-t));
    pr(ans);
}

Measured memory_bytes: 1024
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  if (b >= a)
    Cout("unsafe");
  else
    Cout("safe");
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll MOD = 1e9+7;
    ll ans = 1;
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        ans *= i % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
  lli A,B=1,C=0,D=0,F=0;
  string S;
  cin >> S;
  vector<int>P(26,0);
  A=S.size();
  rep(i,0,A){
    P[S[i]-97]++;
  }
  rep(i,0,A){
    if(P[i]>1){
      Out("no");
      C=2;
      break;
    }
  }
  if(C==0)Out("yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    if(s.size()==2) cout<<s<<endl;
    else{
        RREP(i, 0, s.size()){
            cout<<s[i];
        }
        cout<<endl;
    }
    return 0;
}

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

int main(){
  int N,mod=1000000007;
  cin >> N;
  long long ans10=1,ans9=2,ans8=1;
  for(int i=0;i<N;i++){
    ans10*=10;
    ans10%=mod;
    ans9*=9;
    ans9%=mod;
    ans8*=8;
    ans8%=mod;
  }
  long long ans=(ans10+ans8)%mod;
  ans=ans-ans9;
  while(ans<0){
    ans+=mod;
  }
  cout << ans%mod << endl;
}

Measured memory_bytes: 3624
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0
for keta in range(61):
    now = 0
    for x in a:
        if x&(1<<keta):
            now += 1
    ans += (now*(n-now))*2**keta
    ans %= mod

print(ans)

Measured memory_bytes: 122936
fn input1<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn input_arr<T: std::str::FromStr> () -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().flat_map(str::parse).collect()
}

fn main() {
    let n: usize = input1().unwrap();
    let a: Vec<usize> = input_arr();
    let b: Vec<usize> = input_arr();
    let c: Vec<usize> = input_arr();

    let mut prev = n;
    let mut result = 0;
    for av in a.into_iter() {
        let i = av - 1;
        result += b[i];
        if i == 1 + prev {
            result += c[prev];
        }
        prev = i;
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dat[ohara];
ll bucket[ohara];
const int B=1000;
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>q;
    rep(i,q){
        cin>>a>>b>>c;
        //閉区間です
        if(a==0){
            b--;
            //index-bにcを加算
            dat[b]+=c;
            bucket[b/B]+=c;
        }
        else{
            //index-[b,c]内の総和ansを求める
            b--;c--;
            ans=0;
            //端を揃えます
            while(1){
                if(b>c)break;
                if(b%B==0)break;
                ans+=dat[b];
                b++;
            }
            while(1){
                if(b>c)break;
                ans+=dat[c];
                if(c%B==0)break;
                c--;
            }
            //終わり

            //バケットをみる
            while(1){
                if(b==c||b>c)break;
                int bb=b/B;
                ans+=bucket[bb];
                b+=B;
            }
            //
            Cout(ans);
        }
    }
    return 0;
}


Measured memory_bytes: 4016
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let s: usize = sc.read();


    for b in 2..1000000 {
        let mut cur = n;
        let mut sum = 0;
        while cur > 0 {
            sum += cur % b;
            cur /= b;
        }
        if sum == s {
            println!("{}", b);
            return;
        }
    }

    if n > s {
        for x in (1..1000000).rev() {
            if (n - s) % x != 0 { continue; }
            let b = (n - s) / x + 1;
            if n < b * x { continue; }
            let y = n - b * x;
            if x < b && y < b {
                println!("{}", b);
                return;
            }
        }
    }

    if n == s {
        println!("{}", n + 1);
        return;
    }


    println!("-1");
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=naive")
//#pragma GCC diagnostic ignored "-W"
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int a,b;
        while(~getII(a,b)){
                int ava=1,cnt=0;
                while(ava<b){
                        ava--;
                        ava+=a;
                        cnt++;
                }
                printf("%d\n",cnt);
        }
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))

A.sort()

ans = 0
total = A[0]
for i in range(N-1):
    if total*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
    total += A[i+1]

print(ans+1)


Measured memory_bytes: 20604
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]

using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

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

//k!
ll facctorialMethod(ll k)
{
	ll sum = 1;
	for (ll i = 1; i <= k; ++i)
	{
		sum *= i;
		sum %= MOD;
	}
	return sum;
}

//nCr
ll permutationMethod(ll n, ll r)
{
	ll n_sum, r_sum;
	ll i;
	r = n - r;
	n_sum = facctorialMethod(n);
	r_sum = facctorialMethod(r);
	return n_sum / r_sum;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main()
{
	string s;
	cin >> s;
	rep(i,s.length()){
		if(s[i]=='7'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    char c;
    cin >> c;
    cout << char(c + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
char grid[1005][1005];
int dp[1005][1005];

void disp_grid (int n )
{
	cout << "grid: " << endl;
	rep (i, n ){
		rep (j, n ){
			cout << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
}
void disp_dp (int n )
{
	cout << "dp: " << endl;
	rep (i, n ){
		rep (j, n ){
			cout << dp[i][j];
		} // end rep
		cout << endl;
	} // end rep
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.square_searching", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		memset (grid, 0, sizeof (grid ) );
		memset (dp, 0, sizeof (dp ) );
		rep (i, n ){
			rep (j, n ){
				scanf (" %c", &grid[i][j] );
			} // end rep
		} // end rep

		dp[0][0] = (grid[0][0] == '.' ? 1 : 0 );
		for (int i = 1; i < n; i++ ){
			dp[i][0] = (grid[i][0] == '*' ? 0 : 1 );
		} // end for
		for (int j = 1; j < n; j++ ){
			dp[0][j] = (grid[0][j] == '*' ? 0 : 1 );
		} // end for
		for (int i = 1; i < n; i++ ){
			for (int j = 1; j < n; j++ ){
				dp[i][j] = (grid[i][j] == '*' ? 0 : min (dp[i-1][j-1], min (dp[i-1][j], dp[i][j-1] ) ) + 1 );
			} // end for
		} // end for
		
//		disp_grid (n );
//		disp_dp (n );
		int res = 0;
		for (int i = 1; i < n; i++ ){
			for (int j = 1; j < n; j++ ){
				res = max (res, dp[i][j] );
			} // end for
		} // end for
		printf ("%d\n", res );
	} // end loop

		
	return 0;
}

Measured memory_bytes: 6128
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion



int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	cout << (n - 2) * 180 << endl;

	return 0;
}

Measured memory_bytes: 3628
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n;
    R(n);
    int prv;
    R(prv);
    LL ans=0;
    REP1(i,1,n-1) {
        int x;
        R(x);
        if ( x<prv ) ans+=prv-x;
        else prv=x;
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3812
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    answers = set([1, 2, 3])
    answers.remove(A)
    answers.remove(B)
    for i in answers:
        print(i)
        exit()
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
x = int(input())
if x == 1:
    print(1)
    exit()
ans = 0
for b in range(2, x):
    for p in range(2, 11):
        b_p = b**p
        if b_p <= x:
            ans = max(ans, b_p)
        else:
            break
print(ans)


Measured memory_bytes: 2940
import java.io.FileInputStream;
import java.util.*;

public class Main {
    int n,k;
    void solve() throws Exception {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); k = sc.nextInt();
        System.out.println(n -k +1);

    }

    public static void main(String[] args) throws Exception{
        //System.setIn(new FileInputStream("inputs/a.in"));
        Main s = new Main();
        s.solve();
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
const int t=1000000007;
long long int n,m,i,j,k,l,arr[300009],crr[200009]={},x,y,z;
int main()
{
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&arr[i]);
    for(i=0;i<n;i++){
        m=arr[i];
        l=1;
        while(m){
            j=m%2;
            crr[l]+=j;
            l++;
            m/=2;
        }
    }
    m=0;
    for(i=1;i<1000;i++){
        l=n-crr[i];
        l*=crr[i];
        if(l>0){
        l=l%t;
          x=1;
          y=1;
          while(y<i){
            x*=2;
            y++;
          }
          if(x>0)
            x=x%t;
          l*=x;
        if(l>0)
          l=l%t;
          if(m>0)
            m=m%t;
          m+=l;
          if(m>0)
          m=m%t;
        }
    }
    printf("%lld",m);
    // 1152921504606846976
}


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

int main(){
	int N;
	cin >> N;
	int res = 0;
	int m;
	vector<int> vec(N, 0);
	int divisor;
	for(int n = 1; n <= N; n+=2){
		m = n;
		divisor = 1;
		for(int i = 3; i <= N; i+=2){
			while(m % i == 0){
				vec[i]++;
				m /= i;
			}
		}
		for(int i = 3; i <= N; i+= 2){
			divisor *= (vec[i] + 1);
			vec[i] = 0;
		}
		if(m == 1 && divisor == 8) res++;
		
	}
	cout << res << endl;
}


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

using namespace std;
const int MAXN = 3e5+5;
int arr[MAXN];
int main(){
    int n,k;
    cin>>k>>n;
    if(k%2==0){
        cout<<(k/2)<<" ";
        for(int i=2;i<=n;i++){
            cout<<k<<" ";
        }
    }else{
        for(int i=1;i<=n;i++){
            arr[i] = (k+1)/2;
        }
        int lst = n;
        for(int i=1;i<=(n/2);i++){
            if(arr[lst]!=0){
                arr[lst]--;
            }else{
                while(arr[lst]==0 && lst){
                    lst--;
                }
                
                arr[lst]--;
                if(arr[lst]){
                    for(int j=lst+1;j<=n;j++){
                        arr[j] = k;
                    }
                    lst = n;
                }
            }
        }
       
        for(int i=1;i<=n;i++){
            if(arr[i]){
                cout<<arr[i]<<" ";
            }
        }
    }
    
    cout<<endl;
}

Measured memory_bytes: 3456
S = input()
dic = {}
for i in range(4):
    if S[i] not in dic.keys():
        dic[S[i]] = 1
    else:
        dic[S[i]] += 1

ok = 0


for k in dic.keys():
    if(dic[k] != 2):
        ok = 1

if(len(dic.keys()) == 2 and ok==0):
    print("Yes")
else:
    print("No")

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

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

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int *p = malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++){
        scanf("%d", &p[i]);
    }
    qsort(p, n, sizeof(int), compare_int);
    int sum = 0;
    for (int i = 0; i < k;i++){
        sum += p[i];
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1740
using System;
class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        int lc = input.Length;
        switch(input[lc-1])
        {
            case '2':
            case '4':
            case '5':
            case '7':
            case '9':
                Console.WriteLine("hon");
                break;
            case '0':
            case '6':
            case '1':
            case '8':
                Console.WriteLine("pon");
                break;
            case '3':
                Console.WriteLine("bon");
                break;
        }
    }
}

Measured memory_bytes: 17204
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

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

#define pb push_back
#define mp make_pair
#define mt make_tuple

vector<ll> biggest_n(vector<ll>& As, int N) {

    vector<ll> sums(3*N);
    multiset<ll> kept;

    REP(n, 3*N) {
        auto a = As[n];
        if (n == 0) {
            sums[n] = a;
            kept.insert(a);
        }
        else if (n < N) {
            sums[n] = sums[n-1] + a;
            kept.insert(a);
        }
        else {
            if (*kept.begin() < a) {
                sums[n] = sums[n-1] - *kept.begin() + a;
                kept.erase(kept.begin());
                kept.insert(a);
            }
            else {
                sums[n] = sums[n-1];
            }
        }
    }

    // for(auto s:sums) cout << s << " ";
    // cout << endl;

    return sums;
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> As(3*N);
    REP(n, 3*N) {
        cin >> As[n];
    }

    auto left_largeN = biggest_n(As, N);
    vector<ll> Bs(3*N);
    REP(i, 3*N) {
        Bs[i] = -As[3*N-1-i];
    }
    auto right_smallN = biggest_n(Bs, N);

    ll ans = 0;
    FOR(i, N-1, 2*N) {
        auto val1 = left_largeN[i];
        auto idx = (3 * N - 1) - i - 1;
        auto val2 = -right_smallN[idx];
        // cout << "i, idx = " << i << "," << idx << endl;
        // cout << "val1, val2 = " << val1 << "," << val2 << endl;
        if (i == N-1) ans = val1 - val2;
        else ans = max(ans, val1 - val2);
    }
    cout << ans << endl;

    return 0;
}


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


  
int main(){
  

  int64_t n;
  cin>>n;
  
  vector<int64_t> data(n);
  
  for (int64_t i=0;i<n;i++){
    cin>>data.at(i);
  }
  
  
  int64_t sum=0;
  
  vector<int64_t> sums(n);
  
  for (int64_t i=0;i<n;i++){
    sum+=data.at(i);
    sums.at(i)=sum;
  }
  
  vector<int64_t> difference(n-1);
  
  for (int64_t i=0;i<n-1;i++){
    int64_t tmp=abs(sums.at(n-1)-2*sums.at(i));
    difference.at(i)=tmp;
  }
  
  sort(difference.begin(),difference.end());
 
  cout<<difference.at(0)<<endl;
  
    
  
}

















Measured memory_bytes: 4992
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL a[maxn];

int main() {
    int n;
    read(n);LL tot=0;
    REP(i,1,n) read(a[i]),tot+=a[i];
    LL w=1LL*n*(n+1)/2;
    if(tot%w!=0) {
        printf("NO\n");return 0;
    } tot/=w;
    a[0]=a[n];
    REP(i,1,n) {
        if((tot-(a[i]-a[i-1]))%n) {
            printf("NO\n");return 0;
        }
        LL d=(tot-(a[i]-a[i-1]))/n;
        if(!(0<=d && d<=tot)) {
            printf("NO\n");return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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


int main(){
    ll n;
    cin >>n;
    if(n%2){
        cout << 0 << endl;
        return 0;
    }

    ll k = n/2;
    ll ans = 0;
    while(k >= 5){
        ans += k/5;
        k /= 5;
    }

    cout << ans << endl;

}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
  	int n;
	cin>>n;
	int h[n+1];
	h[0] = INT_MAX;
	for(int i=1;i<=n;cin>>h[i++]);

	int dp[n+1];
	memset(dp,0,sizeof(dp));

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

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

        int x;
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        if (b > c) {
            // b と c　を入れ替える
            x = b;
            b = c;
            c = x;
        }
        if (a > b) {
            //a と b　を入れ替える
            x = a;
            a = b;
            b = x;
        }
        if (b > c) {
            // b と c　を入れ替える
            x = b;
            b = c;
            c = x;
        }
        System.out.println(a+" "+b+" "+c);
    }
}



Measured memory_bytes: 26408
A = input()
B = input()
C = input()

next_p = 'a'
while True:
    if next_p == 'a':
        if A == '':
            print("A")
            break
        next_p = A[0]
        A = A[1:]
#        print(next_p,A)

    if next_p == 'b':
        if B == "":
            print("B")
            break
        next_p = B[0]
        B = B[1:]
#        print(next_p,B)

    if next_p == 'c':
        if C == "":
            print("C")
            break
        next_p = C[0]
        C = C[1:]
#        print(next_p,C)




Measured memory_bytes: 3060
package main

import (
	"fmt"
	"strconv"
)

func solve() {
	var N int
	fmt.Scan(&N)

	if N%al(N) == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")

}

func al(a int) int {
	po := strconv.FormatInt(int64(a), 10)
	ans := 0
	for _, s := range po {
		w, _ := strconv.ParseInt(string(s), 10, 64)
		ans += int(w)
	}
	return ans

}

func main() {
	solve()
}


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

int main() {
  string N;
  cin >> N;
  if (N[0] == N[1]&& N[1] == N[2]){
    cout << "Yes" << endl;
  }
  else if(N[1] == N[2] && N[2] == N[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j) cout<<((i<b)^(j<a));
		cout<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,index=0;
    cin>>n;
    int a[810]={0};
    if(n==0){
        cout << 0<<endl;
        return 0;
    }
    while(n){
        a[index]=n%2;
        n/=-2;
        index++;
    }
    for(int i=0;i<index;i++){
        if(a[i]==-1){
            a[i]=1;
            a[i+1]++;
            index=max(i+2,index);
        }
        else if(a[i]==2){
            a[i]=0;
            a[i+1]++;
            a[i+2]++;
            index=max(i+3,index);
        }
    }
    for(int i=index-1;i>=0;i--){
        cout << a[i];
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 256
// D - XOR World
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll f0(ll n){//f(0,n)
	ll c = 0;
	n++;
	for(int i=0; i<50; ++i){
		ll loop = 1LL<<(i + 1);
		ll cnt = (n/loop) * (loop/2);
		cnt += max(0LL, (n%loop) - (loop/2));
		if(cnt%2==1LL) c += 1LL<<i;
	}
	return c;
}

ll f(ll A, ll B){
	return f0(B) ^ f0(A-1);
}

int main(){
	ll A,B; cin>>A>>B;
	cout<<  f(A,B) <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool end;
};

int main(){
    ll X,N;
    cin>>X>>N;
    ll m=100000,d=100000;
    VEC(ll,p,N);
    REP(i,N){
        cin>>p[i];
    }
    FOR(i,-1,102){
        if(find(ALL(p),i)==p.end()){
            ll tt=abs(X-i);
            if(d==tt){
                
            }else if(d>tt){
                m=i;
                d=tt;
            }
            //sl(i,m,d)
        }
    }
    cout<<m;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

bool judge(long long n, vector<long long> &a, long long k) {
    deque<long long> b;
    for (auto x: a) {
        if (x % n) b.emplace_back(x % n); 
    }
    sort(b.begin(), b.end());
    long long tmp = 0;
    while (!b.empty()) {
        long long t = min(b.front(), n-b.back());
        b.front() -= t; b.back() += t;
        tmp += t;
        if (b.front() % n == 0) b.pop_front();
        if (b.back() % n == 0) b.pop_back();
    }
    return tmp <= k;
}

int main() {
    int n; long long k;
    cin >> n >> k;
    vector<long long> a(n);
    long long sum = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i]; sum += a[i];
    }
    for (long long i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (judge(i, a, k)) ans = max(ans, i);
            if (judge(sum/i, a, k)) ans = max(ans, sum/i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
int n,i,j,A[2000000],x,y;
int fa[2000000],fir[2000000],top,ne[5000000],la[5000000],to[5000000];
bool lost[2000000],win[2000000];
inline void add(int x,int y)
{
	top++,to[top]=y;
	if(fir[x]==0)fir[x]=top;else ne[la[x]]=top;
	la[x]=top;
}
void dfs(int x)
{
	win[x]=false;
	for (int i=fir[x];i;i=ne[i])
	if(to[i]!=fa[x])
	{
		fa[to[i]]=x;
		dfs(to[i]);
		if(win[to[i]]==false&&A[x]>A[to[i]])win[x]=true;
	}
}
void dfs2(int x)
{
	for (int i=fir[x];i;i=ne[i])
	if(to[i]!=fa[x])
	{
		if(win[x]==false&&A[to[i]]>A[x])win[to[i]]=true;
		dfs2(to[i]);
	}
}
inline int read()
{
    char ch=getchar();int ret=0,flag=1;
    while(ch<'0'||ch>'9') {if(ch=='-') flag=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
    return ret*flag;
}
int main()
{
	n=read();
	for (i=1;i<=n;i++)A[i]=read();
	for (i=1;i<n;i++)x=read(),y=read(),add(x,y),add(y,x);
	fa[1]=0;
	dfs(1);
	dfs2(1);
	for (i=1;i<=n;i++)if(win[i])printf("%d ",i);
	return 0;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int q[222];
int cnt=0,l,r;
void work(ll x){
    if(x==0)return ;
    if(x%2==0){
        //int idx=l--;
        work(x-1);
        q[l--]=++cnt;

    }
    else {
        work(x/2);
        q[r++]=++cnt;
    }
}
int main()
{
    ll n;
    scanf("%lld",&n);
    l=100,r=101;
    cnt=0;
    work(n);
    printf("%d\n",cnt*2);
    for(int i=l+1;i<r;i++){
        printf("%d ",q[i]);
    }
    for(int i=1;i<=cnt;i++){
        printf("%d",i);
        if(i!=cnt)printf(" ");
        else printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dI = { 0, 1, 0, -1 };
        static readonly int[] dJ = { 1, 0, -1, 0 };
        //static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>>G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var cin = new Scanner();

            long N = long.Parse(Console.ReadLine());
            long K = 1;
            while (K * (K + 1) / 2 < N) { K++; }
            long ng = K * (K + 1) / 2 - N;
            for(var i = 1; i <= K; i++)
            {
                if (i != ng) { Console.WriteLine(i); }
            }
            
            

            Console.Out.Flush();
        }
        
        struct Edge
        {
            public int from;

            public int to;
            public long dist;
            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }

        }
    }
    public class Scanner
    {
        public int[] ReadSplitInt()
        {
            return ConvertAll(Console.ReadLine().Split(), int.Parse);
        }
        public long[] ReadSplitLong()
        {
            return ConvertAll(Console.ReadLine().Split(), long.Parse);
        }
        public double[] ReadSplit_Double()
        {
            return ConvertAll(Console.ReadLine().Split(), double.Parse);
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }

        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }

        static public long LPow(int a, int b)
        {
            return (long)Pow(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, D, X[10][10];
    cin >> N >> D;
    REP(i, N) REP(j, D) cin >> X[i][j];

    int ans = 0;
    REP(i, N - 1) FOR(j, i + 1, N) {
        int sq = 0;
        REP(k, D) sq += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        REP(k, 10000) {
            if (k * k == sq) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 15;

vector<int> data[N+5];

int check(int mask) {
    for (int i=1,mast=mask; mast; i++,mast>>=1) if (mast & 1) {
        for (int x: data[i]) {
            int temp = 1 << (abs(x) - 1);
            if (x < 0) {
                if ((mask & temp) != 0) return 0;
            } else {
                if ((mask & temp) == 0) return 0;
            }
        }
    }
    return 1;
}

int main() {
    int n; scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        data[i].clear();

        int a; scanf("%d", &a);
        for (int j=1; j<=a; j++) {
            int x,y; scanf("%d %d", &x, &y);
            if (y == 0) x *= -1;
            data[i].push_back(x);
        }
    }

    const int BATS = 1 << n;
    int res = 0;
    for (int mask=0; mask<BATS; mask++) {
        if (check(mask)) res = max(res, __builtin_popcount(mask));
    }

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
while line = gets
  flying_jenny = [1, 4, 1, 4, 1, 2, 1, 2]
  p = line.chomp.split.map(&:to_i)
  answer = []
  n = Float::INFINITY

  flying_jenny.size.times do
    m = 0
    for i in 0...flying_jenny.size
      m += p[i] - flying_jenny[i] if p[i] - flying_jenny[i] > 0
    end

    if m < n
      answer = flying_jenny.dup
      n = [m, n].min
    elsif m == n && (answer.empty? || flying_jenny.join.to_i < answer.join.to_i)
      answer = flying_jenny.dup
    end

    flying_jenny.rotate!
  end

  puts answer.join(' ')
end

Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 3e3;
int dp[MXN+5][MXN+5];
string A,B;


int rec(int ii, int jj){
    if(ii>=A.size() || jj>=B.size()) return 0;
    int &ret = dp[ii][jj];
    if(ret!=-1) return ret;
    if(A[ii]==B[jj]) return ret = rec(ii+1,jj+1) + 1;
    return ret = max ( rec(ii+1,jj) , rec(ii,jj+1) );
}

void watch(){
    for(int i=0; i<A.size(); i++){
        for(int j=0; j<B.size(); j++){
            cout<<setw(2)<<dp[i][j];
        }cout<<"\n";
    }cout<<"\n";
}

void solve(){

    memset(dp,-1,sizeof(dp));
    cin>>A>>B;
    int lcs_len = rec(0,0);
    int i=0,j=0;
    while(lcs_len){
        if(dp[i][j]==dp[i][j+1]) j++;
        else if(dp[i][j]==dp[i+1][j]) i++;
        else{
            cout<<B[j];
            i++,j++;
            lcs_len--;
        }
    }cout<<"\n";


}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 39220
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1, 0);
    vector<int> B(N, 0);
    for (int i = 0; i < N+1; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];

    LL ans = 0;
    for (int i = 0; i < N; i++) {
        int power = B[i];
        if (power <= A[i]) {
            ans += power;
        } else {
            ans += A[i];
            power -= A[i];
            if (power <= A[i+1]) {
                ans += power;
                A[i+1] -= power;
            } else {
                ans += A[i+1];
                A[i+1] = 0;
            }
        }
    }

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


Measured memory_bytes: 1024