akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    int n;


    while (cin >> n) {
        int num = 0;

        for (int a = 0; a <= 9; ++a) {
            for (int b = 0; b <= 9; ++b) {
                for (int c = 0; c <= 9; ++c) {
                    for (int d = 0; d <= 9; ++d) {
                        if (a + b + c + d == n) ++num;
                    }
                }
            }
        }

        cout << num << endl;
    }
}

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

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pll;

ll gcd(ll a, ll b)
{
    if (a < b) {
        swap(a, b);
    }
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main()
{

    ll n, x;
    cin >> n >> x;

    ll g = gcd(n, x);
    ll d = n / g;
    cout << g * (d - 1) * (ll)(3) << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int MAX = 0, MAXid = 0, MIN = 0, MINid = 0;
    rep(i, 0, n){
        cin >> a[i];
        if(MAX < a[i]){
            MAX = a[i]; MAXid = i;
        }
        if(MIN > a[i]){
            MIN = a[i]; MINid = i;
        }
    }
    vector<P> d;
    if(abs(MAX) >= abs(MIN)){
        rep(i, 0, n){
            d.push_back(P(MAXid, i));
        }
        rep(i, 0, n - 1){
            d.push_back(P(i, i + 1));
        }
    }else{
        rep(i, 0, n){
            d.push_back(P(MINid, i));
        }
        repb(i, n - 1, 1){
            d.push_back(P(i, i - 1));
        }
    }
    cout << d.size() << endl;
    for(int ii = 0; ii < d.size(); ii++){
        cout << d[ii].first + 1 << " " << d[ii].second + 1 << endl; 
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  char SA[100],SB[100],SC[100];
  int a=0,b=0,c=0;
  int flag[3]={1,0,0},con=0;
  
  scanf("%s\n%s\n%s",SA,SB,SC);
  
  while(1)
  {
    if(SA[a]=='a'&&flag[0]==1) a++;
    else if(SB[b]=='b'&&flag[1]==1) b++;
    else if(SC[c]=='c'&&flag[2]==1) c++;
    else if(SA[a]=='b'&&flag[0]==1){
      a++;
      flag[0]=0;
      flag[1]=1;
    }
    else if(SA[a]=='c'&&flag[0]==1){
      a++;
      flag[0]=0;
      flag[2]=1;
    }
    else if(SB[b]=='a'&&flag[1]==1){
      b++;
      flag[1]=0;
      flag[0]=1;
    }
    else if(SB[b]=='c'&&flag[1]==1){
      b++;
      flag[1]=0;
      flag[2]=1;
    }
    else if(SC[c]=='a'&&flag[2]==1){
      c++;
      flag[2]=0;
      flag[0]=1;
    }
    else if(SC[c]=='b'&&flag[2]==1){
      c++;
      flag[2]=0;
      flag[1]=1;
    }
    
    if(SA[a]=='\0'&&flag[0]==1){
      printf("A");
      break;
    }
    if(SB[b]=='\0'&&flag[1]==1){
      printf("B");
      break;
    }
    if(SC[c]=='\0'&&flag[2]==1){
      printf("C");
      break;
    }
  }
    
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int A, B,M;
	cin >> A >> B>>M;
	vector<int> a(A),q(A);
	rep(i, A)cin >> a[i];
	q = a;
	vector<int> b(B),w(B);
	rep(i, B)cin >> b[i];
	w = b;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int ans = a[0] + b[0];
	//vector<tuple<int,int,int>>
	rep(i, M) {
		int x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, q[x] + w[y] - c);
	}
	cout << ans;
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
//#include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;

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

const int INF = 2e9;
const LL MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, N;
  cin >> H >> N;
  VI A(N), B(N);
  REP(int, i, N) cin >> A[i] >> B[i];
  VVI dp(N+1, VI(H+1, INF));
  dp[0][0] = 0;
  REP(int, i, N) REP(int, j, H+1)
  {
    dp[i+1][j] = dp[i][j];
    chmin(dp[i+1][j], dp[i+1][max(0, j-A[i])] + B[i]);
  }
  cout << dp[N][H] << endl;

  return 0;
}

Measured memory_bytes: 39424
#include<stdio.h>
#define L 102
#define WHITE 1
#define BLACK 2
#define GRAY 3

int n,count,color[L],d[L],f[L],array[L][L];

void dfsv(u){
  int j;
  color[u]=GRAY;
  d[u]=++count;
  for(j=1;j<=n;j++){
    if((color[j]==WHITE) && (array[u][j]==1)){
      dfsv(j);
    }
  }
  color[u]=BLACK;
  f[u]=++count;
}

void dfs(void){
  int i;
  for(i=1;i<=n;i++){
    color[i]=WHITE;
  }
  count=0;
  for(i=1;i<=n;i++){
    if(color[i]==WHITE){
      dfsv(i);
    }
  }
}

int main(){
  int i,j,number,k,c;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      array[i][j]=0;
    }
  }
  for(i=1;i<=n;i++){
    scanf("%d%d",&number,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&c);
      array[i][c]=1;
    }
  }
  dfs();

  for(i=1;i<=n;i++) printf("%d %d %d\n",i,d[i],f[i]);
  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A[25][25];
ll DP[int(3e6+5)];

int Bit(int num){
  int ans = 0;
  while (num > 0){
    if (num % 2 != 0) ans++;
    num /= 2;
  }
  return ans;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  
  DP[0] = 1;
  for (int i = 0; i < (1<<N); i++){
    int num = Bit(i);

    for (int j = 0; j < N; j++){
      int now = 1 << j;
      int Judge = now & i;
      if (Judge > 0) continue;
      if (A[num][j] == 0) continue;

      DP[now + i] += DP[i];
      DP[now + i] %= MOD;
    }
  }

  cout << DP[(1<<N) - 1] << endl;

  return 0;
}


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

signed main(){
	int a, b, c, ans = 0, i;
	scanf("%d%d%d", &a, &b, &c);
	vector<int> count(101, 0);
	count[a] = 1;
	count[b] = 1;
	count[c] = 1;
	for(i = 0; i <= 100; i++){
		ans += count[i];
	}
	printf("%d\n", ans);
	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  ll c = abs(a - b);
  if (c % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


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

struct data {
  long long l, r;
};

bool operator<(const data &l, const data &r) {
  if(l.r != r.r) return l.r < r.r;
  return l.l < r.l;
}

long long n;
vector<long long> x, l;
vector<long long> dp[2];
vector<data> v;
set<int> st;

long long solve();

int main() {
  cin >> n;
  x.resize(n);
  l.resize(n);
  for(int i = 0; i < n; ++i) cin >> x[i] >> l[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for(int i = 0; i < n; ++i) {
    v.push_back({x[i] - l[i], x[i] + l[i]});
  }
  sort(v.begin(), v.end());
  long long now = (long long)-1e17;
  for(int i = 0; i < n; ++i) {
    if(now <= v[i].l) {
      ++res;
      now = v[i].r;
    }
  }
  return res;
}

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

int main(){

  int n, d, x, count=0;
  cin>>n;
  cin>>d>>x;
  int a[n];

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

  for(int i=0; i<n; i++){
    for(int j=0; j<d; j+=a[i]){
        count++;
    }
  }

  cout<<count+x<<endl;

  return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> a(N), b;
  for(int i=0; i<N; i++) cin >> a.at(i);
  
  b=a; sort(b.begin(), b.end());
  int x=b.at(N/2-1), y=b.at(N/2);
  
  int c;
  for(int i=0; i<N; i++){
    if(a.at(i)<=x) c=y;
    else c=x;
    cout << c << endl;
  }
}

Measured memory_bytes: 3712
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define RREP(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define ALL(vector) vector.begin(), vector.end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, k;
    cin >> h >> w >> k;
    char c[h][w];
    REP(i,h) REP(j,w) cin >> c[i][j];
    int hh = 1 << h;
    int ww = 1 << w;
    //cout<<hh<<' '<<ww<<endl;
    ll ans=0;
    REP(ii,hh){
        REP(jj,ww){
            ll cnt = 0;
            REP(i,h) REP(j,w) {
                if ((ii & (1<<i)) == 0) continue;
                if ((jj & (1<<j)) == 0) continue;
                if (c[i][j] == '#') cnt++;
            }
            if (cnt == k) ans++;
        } 
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
package main

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

func intSlice(str string) []int {
	splitted := strings.Split(str, " ")
	ret := make([]int, len(splitted))

	for i, str := range splitted {
		if strings.TrimSpace(str) != "" {
			n, _ := strconv.Atoi(str)
			ret[i] = n
		}
	}

	return ret
}

func main() {

	stdin := bufio.NewScanner(os.Stdin)

	// 一行目
	stdin.Scan()
	line1 := stdin.Text()
	ints1 := intSlice(line1)
	n := ints1[0]
	k := ints1[1]

	var p float64

	p = 0.0

	for i := 1; i <= n; i++ {

		if i >= k {
			p += 1 / float64(n)
		} else {
			r := math.Ceil(math.Log2(float64(k) / float64(i)))
			p += math.Pow(0.5, r) / float64(n)
		}
	}

	fmt.Printf("%.11f\n", p)
}


Measured memory_bytes: 640
from collections import Counter

n = int(input())
ac_count = 0
wa_count = 0
tle_count = 0
re_count = 0

for _ in range(n):
    c = input()
    if c == "AC":
        ac_count += 1
    elif c == "WA":
        wa_count += 1
    elif c == "TLE":
        tle_count += 1
    else:
        re_count += 1

print("AC x {}".format(ac_count))
print("WA x {}".format(wa_count))
print("TLE x {}".format(tle_count))
print("RE x {}".format(re_count))

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

#define INF 1e9 + 5

// for using in pairs
#define F first
#define S second

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

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

ll lcm(ll a, ll b)
{
	return (a * b) / gcd(a, b);
}

void solve(int tc)
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll L = lcm(c, d);

	a--;

	ll A = b - b / c - b / d + b / L;
	ll B = a - a / c - a / d + a / L;

	cout << A - B << "\n"; 

}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int n, m, p, y;


//vector<int> c[100005];
struct city{
    int idx, year, pos;
    char id[20];
};
bool sortCity(city a, city b){
    if(a.idx == b.idx)
        return a.year > b.year;
    return a.idx > b.idx;

}
bool sortI(city a, city b){
    return a.pos < b.pos;
}
city c[100005];

int main(){
    scanf("%d %d", &n, &m);
    for(int i=0; i<m; i++){
        scanf("%d %d", &p, &y);
        c[i].idx = p;
        c[i].year = y;
        c[i].pos = i;
    }
    sort(c, c+m, sortCity);
    int j = c[m-1].idx;
    int cont = 0;
    for(int i=m-1; i>=0; i--){
        if(j == c[i].idx){
            cont++;
        } else {
            j = c[i].idx;
            cont = 1;
        }
            int p1 = c[i].idx, aux = cont;
            for(int k=5; k>=0; k--){
                //printf("..%d\n", p1%10);
                if(p1 > 0){
                    c[i].id[k] = (p1%10)+'0';
                    p1 /= 10;
                }else {
                    c[i].id[k] = '0';
                }
            }

            for(int k=11; k>=6; k--){
                if(aux > 0){
                    c[i].id[k] = (aux % 10)+ '0';
                    aux /= 10;
                }else {
                    c[i].id[k] = '0';
                }
            }

       // printf("%d %d %d %s\n", c[i].idx, c[i].year, c[i].pos, c[i].id);
    }

    sort(c, c+m, sortI);
    for(int i=0; i<m; i++){
        printf("%s\n",  c[i].id);
    }
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int count=0;
  while(n!=0){
    n--;
    count+=n;
  }
  while(m!=0){
    m--;
    count+=m;
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else {
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    if n == 1 {
        "Hello World".to_string()
    } else {
        input!(input=>(_n:i64)(a:i64)(b:i64));
        (a + b).to_string()
    }
    .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "1" => "Hello World",
    test2: "2\n3\n5" => "8",
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> A = new List<int>();
      static List<int> B = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
//１を中心にしたウニ型をベースに考える。
//1以外の各点から各点の距離は２。これ(N-1個から２点取る)が組み合わせ数最大の形。Kがこれ以上ならムリ。
if((N-1)*(N-2)/2<K){Console.WriteLine("-1");return; }
//ここに一本ずつ線を入れる。線を入れると両者間の距離が１になって一組消える。
M=(N-1)*(N-2)/2-K;//消すべき数量(=線の数)はウニで出来る組み合わせとKとの差異。
Console.WriteLine((M + N-1).ToString()); 
            for(int i=2;i<=N;i++){
Console.WriteLine("1 " + i.ToString());     //ウニを描く
      }
//どの組み合わせでもいいので，とりあえず先頭から消していく。
for(int i=2;i<N;i++){
for(int j=i+1;j<=N;j++){
  if(M==0){return;}//線の本数が足りたら完成。
Console.WriteLine(i.ToString() + " " + j.ToString());
M--;
}
}      
    }
  
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }


}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    if(n<105) cout << 0 <<endl;
    if(n>=105 && n<135) cout << 1 <<endl;
    if(n>=135 && n<165) cout << 2 <<endl;
    if(n>=165 && n<189) cout << 3 <<endl;
    if(n>=189 && n<195) cout << 4 <<endl;
    if(n>=195) cout<< 5 <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    long long int x,ans=0;
    scanf("%lld", &x);
    ans+=(x-(x%11))/11*2;
    if(x%11>=7) ans+=2;
    else if(x%11==0) ans+=0;
    else ans++;
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 128
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;

int main(){


    
    cin >> N;
    cin >> A;
    cin >> B;

    ll set;
    set = A+B;

    ll cntSet;
    cntSet = N/set;
    ll left;
    left = N - cntSet*set;

    cout << cntSet*A + min(left,A) << endl;    

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<sstream>
 
using namespace std;
		
	long long dp[10099][121]; // KONJU NEMORAS SUMU NEGO %moD
	#define MOD 1000000007
	int d; 
	
	long long suma = 0;
	string A; 
	
	void rek(int idx, int pass){
		
		//cout << "kurac" ;
		
		if(idx == A.size()){
		//	cout << pass << " " <<"KRAJ";
			if(pass%d==0)suma++;
			return;
		}
		
		for(int i = 0; i < A[idx] - '0'; i++){
			suma += dp[A.size() - idx - 1][((d - i - pass)%d + 5*d)%d];
			suma %= MOD;
		//	suma = (suma + dp[A.size() - idx - 1][((d - i - pass)%d + d)%d])%MOD;
		//	cout << A.size() - idx - 1 << " " << ((d- i - pass)%d + d)%d << endl;
		//	cout << dp[19][2] << endl;
		//	cout << suma << " " << A.size() - idx - 1 << " " << dp[A.size() - idx - 1][((d - i - pass)%d + 5*d)%d] << " " << ((d - i - pass)%d + 5*d)%d << endl;
		} 
		
		//cout << suma <<  " " << idx << endl; system("pause");
		pass += A[idx] - '0';
		pass%=d;
		
		rek(idx+1,pass);
		
		return;
		
	}
 
int main(){
 
	cin >> A;
	cin >> d;
	
	//cout << d << endl;
	
	//cout << (-1)%222 << endl;
	
	dp[0][0] = 1;
	
	for(int i = 0; i < 10009; i++){
		
		for(int j = 0; j < 111; j++){
			
			dp[i][j]%=MOD;
			
	//		cout << dp[i][j] << " ";
			for(int k = 0; k < 10; k++){
				
				dp[i+1][(j+k)%d] += dp[i][j];
				dp[i+1][(j+k)%d]%=MOD;
				
			}
		}
	//	cout <<endl;
		
	}
	
	//system("pause");
	//suma += dp[B.size()-1][0];
	//cout << suma << endl;
	
	rek(0,0);
	cout <<((suma - 1)%MOD + MOD)%MOD;
	
 
 
 
 
	return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>

typedef long long int llint;

int main(void){
  int h, w, k;
  std::cin >> h >> w >> k;

  std::vector<bool> isthereichigo(h, false);
  std::vector<std::vector<int> > cut(h, std::vector<int>(w));

  int now = 1;
  for(int i=0; i<h; i++){
    char tmp = '.';
    bool first = true;
    for(int j=0; j<w; j++){
      std::cin >> tmp;
      if(tmp == '#'){
	isthereichigo[i] = true;
	if(first) first=false;
        else      now++;
      }
      cut[i][j] = now;
    }
    now++;
  }

  std::vector<int> references(h);
  
  for(int i=0; i<h; i++){
    if(isthereichigo[i]) continue;

    int reference = i==0?i+1:i-1;
    if(i == 0){
      while(!isthereichigo[reference]) reference++;
    }
    for(int j=0; j<w; j++){
      cut[i][j] = cut[reference][j];
    }
  }

  std::map<int, int> amap;

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(amap.find(cut[i][j]) == amap.end()){
	amap[cut[i][j]] = amap.size();
      }
      cut[i][j] = amap[cut[i][j]];
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      std::cout << cut[i][j] << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}


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

int N, Q;
string S;
int L[100010], R[100010];

int main() {
    cin >> N >> Q;
    cin >> S;
    for (int i = 0; i < Q; ++i) cin >> L[i] >> R[i];

    vector<int> ss(N, 0);
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'A') {
            if (S[i + 1] == 'C') ss[i] = 1;
        }
    }

    vector<int> wa(N + 1, 0);
    for (int i = 0; i <= N; ++i) {
        wa[i + 1] = wa[i] + ss[i];
    }

    for (int i = 0; i < Q; ++i) {
        int ans = wa[R[i]] - wa[L[i] - 1];
        if (ss[R[i] - 1] == 1) --ans;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2624
//#define _CRT_SECURE_NO_WORNINGS
#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<map>
#include<stdio.h>


#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define REV(x) reverse((x).begin(),(x).end())
#define endl  ("\n")
#define ll long long

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

const  double PI = 3.142857142857;
struct point{
	ll PP, PPP;
};

using namespace std;
ll arr[1000000];
int main()
{
	FAST

		int n;
	cin >> n;
	ll mx = 0;
	for (int i = 0; i < n; i++){
		cin >> arr[i];
		mx = max(mx, arr[i]);
	}
	ll sum = 0;
	bool ok = 1;
	for (int i = 0; i < n; i++){
		if (arr[i] == mx && ok==1){
			sum += arr[i] / 2;
				ok = 0;
		}
		else sum += arr[i];
	}

	cout << sum << endl;
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  int n = A;
  string ans = "NO";
  while (n < A * B) {
    if (n % B == C) ans = "YES";
    n += A;
  }

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


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

m = [0] * (N + 1)
for i in range(N):
    m[A[i]] += 1
ans = 0
for i in range(len(m)):
    ans += (m[i] * (m[i] - 1) // 2)
for i in range(N):
    print(ans - m[A[i]] + 1)


Measured memory_bytes: 26140
#include<stdio.h>
int main() {
	int i, N, t, A[30], B[30], C[30], ans = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 1; i <= N; i++) {
		scanf("%d", &B[i]);
	}
	for (i = 1; i <= N - 1; i++) {
		scanf("%d", &C[i]);
	}
	A[N + 1] = C[N] = 0;
	for (i = 1; i <= N; i++) {
		ans += B[A[i]];
		if (A[i] + 1 == A[i + 1])
			ans += C[A[i]];
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 128
//
// Created by Tetsuya Shiota on 2019-04-13.
//

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x)                                                                \
  cout << __LINE__ << ' ' << #x << " : ";                                      \
  FOR(e, x) cout << e << ' ';                                                  \
  cout << endl;
#else
#define pp(x)
#define dump(x)
#endif

using namespace std;

using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;

template <typename T> void reverse(vector<T> &v) {
  reverse(v.begin(), v.end());
}

template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }

template <typename T> T sum(const vector<T> &v) {
  return accumulate(v.begin(), v.end(), T(0));
}

template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> bool update_min(T &a, const T &b) { a = min(a, b); }

struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};

class Solver {
public:
  Solver() {}
  vi ans = {-1, -1, -1};
  int N, Y;
  void input() {
    cin >> N >> Y;
    pp(N);
  }
  void solve() {
    rep(i, N + 1) {
      rep(j, N + 1) {
        int now = 0, k = (N - i - j);
        if (k < 0)
          break;
        now += i * 10000;
        now += j * 5000;
        now += k * 1000;
        if (Y == now) {
          ans = {i, j, k};
          dump(ans);
          return;
        }
      }
    }
  }
  void output() { cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl; }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(15) << boolalpha;
  cout.imbue(locale(cout.getloc(), new BoolName));
#ifdef LOCAL
  while (1) {
    Solver s;
    s.input();
    if (cin.eof())
      break;
    s.solve();
    s.output();
  }
#else
  Solver s;
  s.input();
  s.solve();
  s.output();
#endif
}

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

using namespace std;

int ss(int n)
{
    int ret = 0;
    while (n)
        ret++, n /= 10;
    return ret;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += ss(i) % 2;
    cout << cnt << '\n';

    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#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, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}


bool f(int n, vector<bool>& v, vector<bool>& u){
    FOR(i, 2, n){
        u[i] = u[i-2] ^ u[i-1] ^ v[i-1];
    }
    if((u[n-1] ^ u[0] ^ u[1]) == v[0] && (u[n-2] ^ u[n-1] ^ u[0]) == v[n-1]){
        return true;
    }
    return false;
}

signed main(){
    int n;
    string s;
    cin >> n >> s;
    vector<bool> v(n);
    REP(i, n){
        v[i] = (s[i] == 'o' ? 0 : 1);
    }

    for(int i=0; i<=0b11; i++){
        vector<bool> u(n);
        u[0] = i & 1;
        u[1] = (i >> 1) & 1;
        if(f(n, v, u)){
            REP(i, n){
                cout << (u[i] ? 'W' : 'S');
            }
            cout << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 512
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
b.append(0)
c=[0]*(n+1)
for i in range(n):
    if b[i]<a[i]:
        c[i]=b[i]
    else:
        c[i]=a[i]+min(b[i]-a[i],a[i+1])
        a[i+1]-=min(b[i]-a[i],a[i+1])
        
print(sum(c))

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

int N;
vector< pair<int, int> > V;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			printf("? ");
			for (int k = 0; k < N; k++) {
				if (i == k || j == k) printf("1");
				else printf("0");
			}
			printf("\n");
			fflush(stdout);
			int x;
			scanf("%d", &x);
			if (x == 1) V.push_back(make_pair(i, j));
		}
	}
	printf("! ");
	for (int i = 0; i < V.size(); i++) printf("(%d,%d) ", V[i].first, V[i].second);
	printf("\n");
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,K; cin>>N>>K;
  long double P[N]; rep(i,N) cin>>P[i];
  
  long double sum=0,ans=0;
  int l=0;
  rep(i,N){
    sum+=K*(1+P[i])/2;
    if(i<K-1){
      continue;
    }else{
      ans=max(ans,sum/K);
      sum-=K*(1+P[l++])/2;
    }
  }
  cout<<setprecision(15);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <stdio.h>      /* printf */
#include <math.h> 
#include<iostream>
#include <bits/stdc++.h> 
using namespace std;

int main () {
	long long h;
	cin>>h;
	long long ans = 1;
	long long cnt = 1;
	
	while(h != 1){
		h = floor(h/2);
		cnt *= 2;
		ans += cnt;

		//printf("%d %d %d\n",h,cnt,ans );

	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
<?php
error_reporting(0);
//list($H,$W) = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
//$a = explode(" ",trim(fgets(STDIN)));

$len = strlen($N);
if (($N % 2)==0) {
  printf("No\n");
  exit;
}
for($i=0;$i<floor($len/2);$i++) {
  if ($N[$i]!=$N[$len-$i-1]) {
    printf("No\n");
    exit;
  }
}
printf("Yes\n");


Measured memory_bytes: 3828
#include<iostream>
#include<climits>
#include<vector>
using namespace std;
int main()
{
    long long n,i,ma=INT_MIN,mi=INT_MIN,k,c=0;
    cin>>n;
    vector<long long>v;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    ma=v[0];
    k=0;
    for(i=1;i<n;i++)
    {
        if(v[i]>ma)
        {
            ma=v[i];
            k=i;
        }
    }
    for(i=0;i<n;i++)
    {
        if(v[i]==ma)
        {
            c++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(v[i]!=ma)
        {
            mi=max(mi,v[i]);
        }

    }
    if(mi==INT_MIN)
    {
       mi=ma;
    }
   // mi=ma-mi;
   if(c>1)
   {
       for(i=0;i<n;i++)
       {
           cout<<ma<<endl;
       }
   }
   else
   {
    for(i=0;i<n;i++)
    {
        if(v[i]==ma)
        {
            cout<<mi<<endl;
        }
        else
        {
            cout<<ma<<endl;
        }
    }
   }
    cout<<endl;
    return 0;
}


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

int main() {
	ll n,k;
	cin>>n>>k;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	ll c[n]={};
	c[0]=0;c[1]=abs(h[1]-h[0]);
	for(ll i=2;i<n;i++)
	{
	    c[i]=c[i-1]+abs(h[i]-h[i-1]);
	    for(ll j=i-2;i<k?j>=0:i-j<=k;j--)
	    {
	        c[i]=min(c[i],c[j]+abs(h[i]-h[j]));
	    }
	}
	cout<<c[n-1];
	return 0;
}

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

int main()
{
    int n,a,b,c,d;
    cin>>n;
    d=n%10;n=n/10;
    c=n%10;n=n/10;
    b=n%10;n=n/10;
    a=n%10;

    if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
    else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if(a-b-c-d==7)cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, A;
    cin >> N >> A;
    
    int num500 = N / 500;
    int sub = N - 500 * num500;

    if (sub > A) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int phase = 1;
    int i = 1;
    int x = 0;
    while (phase != 0) {
      switch (phase) {
      case 1:
        x = i;
        if ( x % 3 == 0 ){
          System.out.printf(" %d", i);
          phase = 3;
          continue;
        }
      case 2:
        if ( x % 10 == 3 ){
          System.out.printf(" %d", i);
          phase = 3;
          continue;
        }
        x /= 10;
        if (x != 0) {phase = 2;continue;}
      case 3:
        if ( ++i <= n ) {phase = 1;continue;}
      }
      System.out.printf("\n");
      phase = 0;
    }
  }
}



Measured memory_bytes: 41320
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;



struct Q{
    int id = 0;
    string city="";
    int point = 0;
    Q(){
        id=0;
        city="";
        point=0;
    }
};
bool comp(const Q &a,const Q &b){
    if(a.city==b.city){
        return a.point > b.point;
    }
    else{
        return a.city < b.city;
    }
}
int main(){
    int n;
    cin >> n;
    vector<Q> V(n, Q());
    rep(i,n) {
        V[i].id=i+1;
        cin >> V[i].city >> V[i].point;
    }
    sort(ALL(V), comp);
    rep(i,n){cout << V[i].id << endl;}
    return 0;
}

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

#define int long long

int Len[55]; // Len[level]: levelバーガー全体の長さ
int Pat[55]; // Pat[level]: levelバーガーのパティ数

// levelとlayerを投げると、パティ数が返ってくる関数
int rec(int level, int layer) {
  // レベル0は例外
  if (level == 0) {
    return 1;
  }

  if (layer == 1) { // 範囲1
    return 0;
  } else if (layer <= Len[level-1] + 1) { // 範囲2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1] + 2) { // 範囲3
    return Pat[level-1] + 1;
  } else if (layer <= 2 * Len[level-1] + 2) { // 範囲4
    return Pat[level-1] + 1 + rec(level-1, layer - Len[level-1] - 2);
  } else { // 範囲5
    return 2 * Pat[level-1] + 1;
  }
}

signed main() {
  // 入力
  int N, X;
  cin >> N >> X;

  // バーガーの長さとパティの数を前計算
  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3; // レベルi-1バーガー２つ + バン２つ + パティ１つ
    Pat[i] = Pat[i-1] * 2 + 1; // レベルi-1バーガー２つ + パティ１つ
  }

  // 出力
  cout << rec(N, X) << endl;

   return 0;
}


Measured memory_bytes: 256
N=int(input())
inp=list(map(int,input().split(' ')))
su=sum(inp)
ab=su
for i in range(N):
  s1=0
  for j in range(i):
    s1+=inp[j]
  if (ab>abs(2*s1-su)):
    ab=abs(2*s1-su)
print(ab)

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

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

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	
	now := scanInt()
	ans,c := 0,0
	for i := 0; i < n-1; i++ {
		next := scanInt()
		if now >= next {
			c++
		} else {
			ans = max(ans,c)
			c = 0
		}
		now = next
	}
	
	fmt.Println(max(ans,c))
}


Measured memory_bytes: 2304
// https://atcoder.jp/contests/abc130/tasks/abc130_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

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

const MOD: i64 = 1e9 as i64 + 7;

fn main() {
    input! {
        n: usize, m: usize,
        s: [i32; n],
        t: [i32; m]
    };

    let mut dp = dvec!(0; n+1, m+1);
    let mut dp2 = dvec!(0; n+1, m+1);
    dp[0][0] = 0;
    dp2[0][0] = 0;
    for i in 0..n+1 {
        for j in 0..m+1 {
            if i >= 1 && j >= 1 {
                if s[i-1] == t[j-1] {
                    dp[i][j] = dp2[i-1][j-1] + 1;
                    dp[i][j] %= MOD;
                }
                dp2[i][j] = dp2[i-1][j] + dp2[i][j-1] + MOD - dp2[i-1][j-1];
                dp2[i][j] += dp[i][j];
                dp2[i][j] %= MOD;
            }
        }
    }

    let mut hoge = 1;
    for i in 0..n+1 {
        for j in 0..m+1 {
            hoge += dp[i][j];
            hoge %= MOD;
        }
    }
    println!("{}", hoge);
}


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

int main() {
		
	ll a,b,n;
	cin >> a>> b>>n;
	// for(int i=0;i<=n;i++){
	// 	cout << "i:" << i << " " << (a*i)/b - a*(i/b) << endl;
	// }

	if(n>=b){
		// cout << "hi\n";
		cout << ( (a*(b-1)) /b) - a*( (b-1)/b ) << endl;
	}else{
		cout << (a*n)/b - a*(n/b) << endl;
	}

	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;


int main(){
    int n;
    long long k;
    cin>>n>>k;
    vector<long long> a(100001,0);
    for (int i=0; i<n; i++){
        int A,B;
        cin>>A>>B;
        a[A]+=B;
    }
    for (int i=0; i<=100000; i++){
        if(k<=a[i]){
            cout<<i<<endl;
            break;
        }
        k-=a[i];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define Imax 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  asort(a);
  int count=0;
  rep(i,0,n-1) count+=a[i];
  if(a[n-1]<count) cout<<"Yes";
  else cout<<"No";
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

void main()
{
  auto n = readln.chomp.to!size_t;
  auto s = new int[](n);
  foreach (i; 0..n) s[i] = readln.chomp.to!int;
  auto t = s.sum;

  auto dp = BitArray();
  dp.length = t+1;
  dp[0] = true;

  foreach (i; 0..n+1) {
    auto dp2 = dp.dup;
    dp2.lshift(s[i]);
    dp |= dp2;
  }

  foreach_reverse (i; 0..t+1)
    if (dp[i] && i % 10 != 0) {
      writeln(i);
      return;
    }

  writeln(0);
}

auto lshift(ref BitArray ba, size_t n)
{
  if (n % 64 == 0) {
    if (n > 0) {
      ba <<= 1;
      ba <<= n-1;
    }
  } else {
    ba <<= n;
  }
}


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}
int main(){
	int GCD=0,MAX=0;
	int n,r,x;
	scanf("%d%d",&n,&r);
	rep(k,n){
		scanf("%d",&x);
		GCD=gcd(GCD,x);
		MAX=max(MAX,x);
	}
	if(MAX>=r&&r%GCD==0)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 764