akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k; ll ans = 0;
  
  rep(i,n){
    ll x; cin >> x;
    if( x >= k ) ans++;
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;



int main(){
    int n, m; cin >> n >> m;
    vector<int> divisor;
    for(int i = 1; i * i <= m; ++i){
        if(m % i == 0){
            divisor.push_back(i);
            if(i*i != m) divisor.push_back(m/i);
        }
    }    
    sort(ALL(divisor));
    for(auto elem : divisor){
        if(elem < n) continue;
        cout << m/elem << endl;
        return 0;
    }
    return 0;
}

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

dp = [0 for _ in range(N)]

for i in range(1, N):
  dp[i] = min([dp[i-j-1]+abs(h[i]-h[i-j-1]) for j in range(min(i,K))])

print(dp[N-1])


Measured memory_bytes: 56544
# -*- coding: utf-8 -*-
A=int(input())
B=int(input())
if A==1:
    if B==2:
        C=3
    if B==3:
        C=2
if A==2:
    if B==1:
        C=3
    if B==3:
        C=1
if A==3:
    if B==1:
        C=2
    if B==2:
        C=1

print(C)

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

int main(){
  ll n, x, m;
  cin >> n >> x >> m;
  vector<ll> u(m+1);
  u[x] = 1;
  ll p = 2;
  ll c = (x*x) % m;
  while(!u[c]) {
    u[c] = p++;
    c = (c * c) % m;
  }
  ll ans = 0;
  if(n <= u[c]) {
    for(int i = 1; i <= n; i++) {
      ans += x;
      x = (x * x) % m;
    }
  } else {
    for(int i = 1; i < u[c]; i++) {
      ans += x;
      x = (x * x) % m;
    }
    ll cycle = p - u[c];
    ll sum = c;
    ll y = (c * c) % m;
    while(y != c) {
      sum += y;
      y = (y * y) % m;
    }
    ans += sum * ((n-u[c]+1)/cycle);
    ll res = (n-u[c]+1) % cycle;
    rep(i,res) {
      ans += c;
      c = (c * c) % m;
    } 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4012
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

struct union_find {
	struct node {int p, r = 0;};
	vector<node> nodes;

	union_find(int n) : nodes(n) {
		int i = 0;
		for (node &n: nodes)
			n.p = i++;
	}
	int find(int x) {
		int &p = nodes[x].p;
		if (p != x)
			p = find(p);
		return p;
	}
	void unite(int a, int b) {
		int ar = find(a), br = find(b);
		node &an = nodes[ar], &bn = nodes[br];
		if (an.r > bn.r)
			bn.p = ar;
		else {
			an.p = br;
			if (an.r == bn.r)
				bn.r++;
		}
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
};

struct edge {
	int s, t, w;
	bool operator < (edge &a) {return w < a.w;}
};

int main() {
	for (int n; (n = in());) {
		union_find V(n);
		vector<edge> E(in());
		int r = 0;
		for (edge &e: E)
			e = {in(), in(), in()};
		sort(E.begin(), E.end());
		for (edge e: E)
			if (!V.same(e.s, e.t)) {
				r += e.w;
				V.unite(e.s, e.t);
			}
		outl(r);
	}
}


Measured memory_bytes: 2436
lis = [int(i) for i in input().split()]

N = lis[0]
L = lis[1]

if (L + N - 1)>0 and L < 0:
    print(int((L + L + N - 1)*N/2))
elif (L + N - 1) > 0:
    print(int((L + L + N - 1)*N/2 - L))
else:
    print(int((L + L + N - 1)*N/2 - (L + N - 1)))

Measured memory_bytes: 3064
import bisect

n = int(input())
lis = list(map(int,input().split()))
lis.sort()

d = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        b = bisect.bisect_left(lis, int(lis[i] + lis[j]))
        d += b - j - 1
print(d)


Measured memory_bytes: 42972
n = int(input())
h = list(map(int, input().split()))
max_value = 0
cnt = 0
for i in range(1, n):
	if h[i-1] >= h[i]:
		cnt += 1
	else:
		max_value = max(max_value, cnt)
		cnt = 0

if cnt > max_value:
	max_value = cnt
print(max_value)

Measured memory_bytes: 14252
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int r = input.nextInt();
        int c = input.nextInt();
        int[][] matrix = new int[r+1][c+1];
        for (int i = 0; i < r; i++) {
            int sum = 0;
            for (int j = 0; j < c; j++) {
                matrix[i][j] = input.nextInt();
                sum += matrix[i][j];
            }
            matrix[i][c] = sum;
        }
        for (int i = 0; i < c + 1; i++) {
            int sum = 0;
            for (int j = 0; j < r; j++) {
                sum += matrix[j][i];
            }
            matrix[r][i] = sum;
        }
        for (int i = 0; i < r + 1; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < c + 1; j++) {
                sb.append(matrix[i][j]).append(' ');
            }
            System.out.println(sb.toString().trim());
        }
    }
}

Measured memory_bytes: 34780
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
int main(){
    int k,s;
    cin>>k>>s;
    int res = 0;
    rep(0,x,k+1){
        rep(0,y,k+1){
            if(x+y <= s && x+y >= s-k) res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// --- DEBUG begin --- cut here ---
template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}
// --- DEBUG end --- cut here ---

typedef pair<ll, ll> Pair;

ll solve() {
  ll N, X, D; cin >> N >> X >> D;
  if (D == 0 && X == 0) return 1;
  if (D == 0) return N+1;
  if (D < 0) {
    X = X + (N-1) * D;
    D = -D;
  }

  map<ll, vector<Pair>> rec;
  bool zeroP = false;
  ll xshift = X % D;
  if (xshift < 0) xshift += D;
  for (ll k = 1; k <= N; k++) {
    // l * D + k * X ... r * D + k * X     step = D
    ll l = (k-1) * k / 2;
    ll r = (2*N - k - 1) * k /2;
    ll q = (k * xshift) % D;
    ll left  = l + (k * X - q) / D;
    ll right = r + (k * X - q) / D;
    if (q == 0 && left <= 0 && right >= 0) zeroP = true;
    rec[q].emplace_back(left, right);
  }
  ll cnt = 0;
  for (auto z : rec) {
#if DEBUG    
    ll q = z.first;
#endif
    auto vec = z.second;
    sort(vec.begin(), vec.end());
    DLOG("q", q, "vec", vec);
    ll prev = LLONG_MIN;
    for (Pair w : vec) {
      ll l = w.first;
      ll r = w.second;
      if (r <= prev) continue;
      cnt += r - max(l-1, prev);
      prev = r;
    }
  }
  if (!zeroP) cnt++;
  return cnt;

}


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  cout << solve() << endl;
  return 0;
}



Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n,t;
  cin>>n>>t;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int ma[n+1],mal[n+1];
  ma[n]=0;mal[n]=n;
  for(i=n-1;i>=0;i--){
    if(a[i]>ma[i+1]){
      ma[i]=a[i];
      mal[i]=i;
    }else{
      ma[i]=ma[i+1];
      mal[i]=mal[i+1];
    }
  }
  vector<pll> v;
  for(i=0;i<n-1;i++){
    if(ma[i+1]-a[i]>0){
      v.push_back(pll(ma[i+1]-a[i],mal[i+1]));
    }
  }
  sort(v.begin(),v.end(),greater<pll>());
  cnt=1;
  for(i=1;i<v.size();i++){
    if(v[i-1].first>v[i].first)break;
    if(v[i-1].second!=v[i].second)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3572
package main
import "fmt"

func imin(a ...int) (int){
	min := a[0]
    for _, v := range a {
        if v < min {
            min = v
        }
    }
    return min
}

func imax(a ...int) (int){
	max := a[0]
    for _, v := range a {
        if v > max {
            max = v
        }
    }
    return max
}

func main() {
	var n,k int
	fmt.Scan(&n, &k)
	if n%k==0{
		fmt.Println(0)
	}else{
		fmt.Println(1)
	}
}

Measured memory_bytes: 512
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &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...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
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 HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    priority_queue<int>AA;
    int N,M; R(N,M);
    FOR(i,1,N){
        int x;
        R(x);
        AA.push(x);
    }
    REP(i,M){
        if(SZ(AA)==0)break;
        int v=AA.top();
        AA.pop();
        if(v>1)AA.push(v/2);
    }
    LL an=0;
    while(!AA.empty()){
        an+=AA.top();
        AA.pop();
    }
    W(an);
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#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 = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    ll s = 0;
    ll z = 0, o = 0;
    ll n = 0;
    REP(i, N - 1)
    {
        if (S[i] == S[i + 1])
            s++;
        else
        {
            n++;
            if (S[i] == 'R')
                z++;
            if (S[i] == 'L')
                o++;
        }
    }

    n = (n + 1) / 2;

    if (n <= K)
    {
        s = N - 1;
    }
    else
    {
        s += 2 * K;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
import numpy as np
n = int(input())
c = np.zeros((10,10))
for i in range(1,n+1):
  l = int(str(i)[0])
  r = int(str(i)[-1])
  c[l,r] += 1

count = 0
for l in range(10):
  for r in range(10):
    count += c[l,r]*c[r,l]
print(int(count))
  
  



Measured memory_bytes: 12500
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	vector<tuple<int,int>> in;
	vi ps;
	
	rep(i, n){
		int a, b; cin >> a >> b;
		in.emplace_back(a, b);
		ps.pb(a);
	}
	sort(all(ps)); ps.erase(unique(all(ps)), ps.end());
	
	int N = ps.size();
	vi sum(N + 1);
	for(auto i : in){
		int a, b; tie(a, b) = i;
		if(b) sum[lower_bound(all(ps), a) - ps.begin()] ^= 1;
	}
	for(int i = N; i > 0; i--) sum[i] ^= sum[i - 1];
	
	vector<vector<pi>> e(N + 1);
	vi ans, v(N + 1);
	
	for(int i = 1; i <= m; i++){
		int l, r; cin >> l >> r;
		l = lower_bound(all(ps), l) - ps.begin();
		r = upper_bound(all(ps), r) - ps.begin();
		if(l == r) continue;
		e[l].emplace_back(r, i);
		e[r].emplace_back(l, i);
	}
	
	function<void(int)> rec = [&](int c){
		v[c] = 1;
		for(pi i : e[c]) if(!v[i.first]){
			rec(i.first);
			if(sum[i.first]){
				sum[c] ^= 1;
				sum[i.first] = 0;
				ans.pb(i.second);
			}
		}
	};
	
	rep(i, N + 1) if(!v[i]){
		rec(i);
		if(sum[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	sort(all(ans));
	
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\n":" ");
	return 0;
}

Measured memory_bytes: 17140
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll int, ll int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

string s;
string t;
int m;
int n;

int nexts[30][300000];

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

  m = s.size(); n = t.size();
  s = s + s;

  Rep(i, 2*m+2) {
    Rep(j, 30) {
      nexts[j][i] = -1;
    }
  }

  for (int i=2*m-1;i>=0;--i) {
    Rep(j, 26) {
      nexts[j][i] = nexts[j][i+1];
    }

    nexts[s[i] - 'a'][i] = i+1;
  } 

  //Rep(i, 2*m) {
  //  Rep(j, 26) cout << nexts[j][i] << " ";
//
  //  cout << "\n";
  //}

  ll int ans = 0;
  int pos = 0;

  Rep(i, n) {
    int data = nexts[t[i] - 'a'][pos];

    //cout << pos << data << "\n";

    if (data == -1) {
      ans = -1;
      break;
    } else {
      int tmp = pos;
      pos = data;
      ans += pos - tmp;
      pos %= m;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 35072
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s == "RRR"){
    cout << "3\n";
    return 0;
  }
  if(s == "RRS" || s == "SRR"){
    cout << "2\n";
    return 0;
  }
  if(s == "SSS"){
    cout << "0\n";
    return 0;
  }
  cout << "1\n";
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, x;
	cin >> n >> x;
	vector<ll> b(n + 1);
	b[0] = 1;
	rrep(i, n + 1) b[i] = 2 * b[i - 1] + 3;
	vector<ll> p(n + 1);
	p[0] = 1;
	rrep(i, n + 1) p[i] = 2 * p[i - 1] + 1;
	function<long long(long long, long long)> Dfs = [&](long long L, long long now_x) {
		if (L == 0) return 1LL;
		ll ret = 0;
		if (now_x >= 1) now_x--;
		if (now_x >= 1) {
			if (now_x >= b[L - 1]) {
				now_x -= b[L - 1];
				ret += p[L - 1];
			}
			else {
				ret += Dfs(L - 1, now_x);
				now_x = 0;
			}
		}
		if (now_x >= 1) now_x--, ret++;
		if (now_x >= 1) {
			if (now_x >= b[L - 1]) {
				now_x -= b[L - 1];
				ret += p[L - 1];
			}
			else {
				ret += Dfs(L - 1, now_x);
				now_x = 0;
			}
		}
		return ret;
	};
	ll ans = Dfs(n, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 2* 100 * 1000 + 47;



struct RMQ
{
    int T[MAX << 4];
    
    void push(int v, int tl, int tr)
    {
        if (!T[v] || tl == tr)return;
        T[v+v] = T[v+v+1] = T[v];
        T[v] = 0;
    }
    
    void set(int v, int tl, int tr, int l, int r, int x)
    {
        if (r < l)return ;
        push(v, tl, tr);
        if (l == tl && r == tr)
        {
            T[v] = x;
            return ;
        }
        int tm = (tl + tr) / 2;
        set(v + v, tl, tm, l, min(r, tm), x);
        set(v + v + 1, tm+1, tr, max(tm+1, l), r, x);
    }
    
    int get(int v, int tl, int tr, int pos)
    {
        if (tl == tr)return T[v];
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        if (pos <= tm)return get(v + v, tl, tm, pos);
        else return get(v+v+1, tm+1, tr, pos);
    }
};

RMQ T;
int L[MAX], R[MAX];
int A[MAX];
int n, k, sz;
LL D[MAX];



LL F(int x)
{
    int f = T.get(1, 1, sz, x);
    if (!f)return 0;
    int a = A[L[f]] - A[x];
    if (a < 0)a += k;
    return D[f] + a;
}


int main()
{
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &n, &k);
    LL s = 0;
    int prev = 0;
    FOR(i, 1, n+1)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a *= 2;
        s += a;
        if (b == 1 && a > k)
        {
            printf("-1\n");
            return 0;
        }
        a = (prev - a % k + k) % k;
        if (b == 1)L[i] = prev, R[i] = a;
        else L[i] = 0, R[i] = k-1;
        prev = a;
    }
    FOR(i, 1, n+1)
        A[i + i - 1] = L[i],
        A[i + i] = R[i];
    sort(A + 1, A + n + n + 1);
    sz = unique(A + 1, A + n + n + 1) - A - 1;
    
    FOR(i, 1, n+1)
    {
        L[i] = lower_bound(A + 1, A + sz + 1, L[i]) - A;
        R[i] = lower_bound(A + 1, A + sz + 1, R[i]) - A;
    }
    
    RFOR(i, n+1, 1)
    {
        D[i] = F(L[i]);
        if (L[i] > R[i])
        {
            T.set(1, 1, sz, R[i] + 1, L[i] - 1, i);
        }
        else
        {
            T.set(1, 1, sz, 1, L[i]-1, i);
            T.set(1, 1, sz, R[i]+1, sz, i);
        }
    }

    
    
    LL ans = D[1];
    FOR(i, 1, sz+1)
    {
     //   cout << F(i) << endl;
        ans = min(ans, F(i));
    }
    ans += s;
    printf("%lld\n", ans);
    
    
    
    return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	while(n>0){
		if(n%10==7){
			cout << "Yes" << endl;
			break;	
		}
		n = n/10;
	}
	if(n<=0)
		cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =1000000007;
const int INV2 = (MOD+1)/2;



     signed main(){
 int n,m;
 cin>>n>>m;
 int a,b;
 set<int> s;
 for(int i=0;i<m;i++){
   cin>>a>>b;

   if(a==1){
     if(s.find(b)!=s.end()){
       cout<<"POSSIBLE";
       return 0;
     }
     s.insert(b);
   }
   if(b==n){
     if(s.find(a)!=s.end()){
       cout<<"POSSIBLE";
       return 0;
     }
     s.insert(a);
   }
 }
 cout<<"IMPOSSIBLE";
 return 0;




}


        


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define PI  3.1415926535
int main()
{
int a,b,h,m;
double an,c,d;
cin>>a>>b>>h>>m;
c=abs(11.0*m-60.0*h);
an=c/2.0;
if(an>180)
    an=360.0-an;
if((int)(an)==90)
    d=sqrt(a*a+b*b);
else{
    d=a*a+b*b-2*a*b*cos(an*PI/180);
d=sqrt(d);}
cout<<fixed<<setprecision(15)<<d<<endl;

return 0;
}


Measured memory_bytes: 4164
using System;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class ALDS1_11_D
{
    public struct Node
    {
        public int Id;
        public List<int> Adj;
        public int Group;
        public Node(int id)
        {
            Id = id;
            Adj = new List<int>();
            Group = -1;
        }
    }

    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();;
        int n = line[0];
        int m = line[1];

        var g = new Node[n];
        for (int i = 0; i < n; i++)
        {
            g[i] = new Node(i);
        }
        for (int i = 0; i < m; i++)
        {
            int[] val = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            g[val[0]].Adj.Add(val[1]);
            g[val[1]].Adj.Add(val[0]);
        }

        var q = new Queue<int>();
        int group = 0;
        for (int i = 0; i < n; i++)
        {
            if (g[i].Group != -1)
            {
                continue;
            }
            group++;
            q.Enqueue(i);
            g[i].Group = group;
            Bfs(group, g, q);
        }

        int qNum = int.Parse(Console.ReadLine());

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < qNum; i++)
        {
            int[] val = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            if (g[val[0]].Group == g[val[1]].Group)
            {
                sb.Append("yes");
            }
            else
            {
                sb.Append("no");
            }
            sb.AppendLine();
        }
        Console.Write(sb.ToString());
    }

    public static void Bfs(int group, Node[] g, Queue<int> queue)
    {
        while (queue.Count > 0)
        {
            var i = queue.Dequeue();
            for (int j = 0; j < g[i].Adj.Count; j++)
            {
                if (g[g[i].Adj[j]].Group == -1)
                {
                    g[g[i].Adj[j]].Group = group;
                    queue.Enqueue(g[i].Adj[j]);
                }
            }
        }
    }
}



Measured memory_bytes: 35548
#include <iostream>

using namespace std ;

int main()
{
    int age ;
    int y ;
    cin >> age >> y ;
    if (age <=100 && age>=0 && y <=1000 && y >= 0)
    {
        if (age >= 13 )
        cout<<y<<endl;
        else if (age <=12 && age >= 6)
        cout<<y / 2 ;
        else if (age <= 5)
        cout<<0<<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 m = sc.nextInt();
        int l = sc.nextInt();
        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        long[][] c = new long[n][l];

        for(int i = 0; i < n; i++) {
        	for(int j = 0; j < m; j++) {
        		int x = sc.nextInt();
        		a[i][j] = x;
        	}
        }

        for(int i = 0; i < m; i++) {
        	for(int j = 0; j < l; j++) {
        		int x = sc.nextInt();
        		b[i][j] = x;
        	}
        }

        for(int i = 0; i < n; i++) {
        	for(int j = 0; j < m; j++) {
        		for(int k = 0; k < l; k++) {
        			c[i][k] += a[i][j] * b[j][k];
        		}
        	}
        }

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < l-1; j++) {
                System.out.print(c[i][j] + " ");
            }
            System.out.println(c[i][l-1]);
        }
    }
}


Measured memory_bytes: 53684
main = do
  n <- getLine
  s <- getContents
  putStr $ sUnlines $ map judge $ mReadSD $ linesWords s

linesWords s = map words $ lines s
mReadSD    s = map (map (read :: String -> Double)) s
sUnlines   s = unlines $ map show s

judge [xa,ya,ra,xb,yb,rb]
  | x_b >  (ra + rb)      =  0
  | x_b >= abs (ra - rb)  =  1
  | ra > rb               =  2
  | otherwise             = (-2)
  where
    x_b = sqrt ((xa-xb)^2 + (ya-yb)^2)

Measured memory_bytes: 4420
def main():
    n = int(input())
    x = input()
    k = int(x, 2)
    p = x.count("1")
    if p > 1:
        kp0 = k % (p - 1)
    kp1 = k % (p + 1)
    f = [0] * (n + 1)
    for i in range(1, n + 1):
        f[i] = f[i % bin(i).count("1")] + 1
    for i in range(n):
        if x[i] == "1":
            pi = p - 1
            if pi == 0:
                print(0)
                continue
            print(f[(kp0 - pow(2, n - i - 1, pi)) % pi] + 1)
        else:
            pi = p + 1
            print(f[(kp1 + pow(2, n - i - 1, pi)) % pi] + 1)


if __name__ == '__main__':
    main()


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

int n,k,mod=1e9+7,ans=0;
int a[100005];

int quick_power(int a,int b)
{
    int res=1;
    for (;b;b=b>>1,a=(a*a)%mod)
    {
        if (b&1)  res=(res*a)%mod;
    }
    return res;
}

signed main()
{
    cin>>n>>k;
    for (int i=k;i>=1;i--)
    {
        a[i]=quick_power(k/i,n)%mod;
        for (int j=2*i;j<=k;j+=i)  
            a[i]=a[i]-a[j];
    }
    for (int i=1;i<=k;i++)  ans=(ans+a[i]*i)%mod;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 4376
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        long s = scanner.nextLong();

        HashSet<Long> observed = new HashSet<>();
        observed.add(s);

        long prev = s;

        for(int i=2; i<1000000; i++){

            long candidate;
            if(prev%2 == 0){
                candidate = prev / 2;
            }else{
                candidate = 3 * prev + 1;
            }

            if(observed.contains(candidate)){
                System.out.println(i);
                return;
            }else{
                observed.add(candidate);
                prev = candidate;
            }
        }

    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    int t = 1;
    // cin >> t;
    
    while(t--) {
        int n;
        cin >> n;
        
        string s;
        cin >> s;
        
        int r = 0;
        for (auto x: s) {
            if (x == 'R')
                ++r;
        }
        
        int res = r;
        for (int i = 0; i < r; i++) {
            if (s[i] == 'R')
                --res;
        }
        
        cout << res << endl;
    }

	return 0;
}

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

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

  for (int i=1; i<n+1; i++) {
    int dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    int dt = t[i] - t[i-1];
    if (dt >= dist && (dt - dist) % 2 == 0) {
      continue;
    }
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll X;
    cin >> X;
    ll ans = 0;
    ans += (X / 500) * 1000;
    X -= (X / 500) * 500;
    ans += (X / 5) * 5;

    cout << ans << endl;
}


Measured memory_bytes: 256
def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                v = A[j]
                A[j] = A[j - 1]
                A[j - 1] = v
                count += 1
                flag = 1
    print(' '.join(map(lambda x: str(x), A)))
    print(count)
    return(A)
N = input()
# for r in range(N):
line = raw_input()
line = line.strip().split()
line = map(lambda x: int(x), line)
bubbleSort(line, N)



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 N;
vector<int64> A;
map<PLL, int64> dp[19][19];

int64 dfs(int64 l, int64 r, int64 xl, int64 xr) {
    if (dp[l][r].count(PLL(xl, xr))) return dp[l][r][PLL(xl, xr)];
    int64 ret = INF_LL;
    if (l == r) return 0;
    FOR(i, l, r) {
        chmin(ret, (xl+xr)*A[i] + dfs(l, i, xl, xl+xr) + dfs(i+1, r, xl+xr, xr));
    }
    return dp[l][r][PLL(xl, xr)] = ret;
}

int main(void) {
    cin >> N;
    A.resize(N);
    for (auto &x : A) cin >> x;
    cout << dfs(1, N-1, 1, 1) + A[0] + A.back() << endl;
}

Measured memory_bytes: 16640
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n = nextInt();
        int d = nextInt();
        
        int con = 0;
        long x,y;
        //int[][] arr = new arr[2][n];
        for(int i=0;i<n;i++){
            x = nextInt();
            y = nextInt();
            if(Math.sqrt(x*x+y*y)<=d){
                con +=1;
            }
        }
        print(con);

    }


    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    //print
    public static void print(Object a){
        System.out.println(a);
    }


    //gcd
    public static int gcd (int a, int b){
        int tmp;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return b;
    }


    //lcm
    public static int lcm(int a,int b){
        int tmp;
        long c = a;
        c *= b;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return (int)(c/b);
    }
}

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

int main() {
  int N;
  cin >> N;
  if (N / 10 / 9 == 1) {
    cout << "Yes" << endl;
  }
  else if (N % 10 / 9 == 1) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = -1; ll z = 0, o = 1;
vl flag, color, D; vll path; ll pre = 0;
map<ll, ll> primeFactorize(ll n, map<ll, ll>& PF) {
	while (n % 2 == 0) {
		PF[2]++;
		n /= 2;
	}
	for (ll p = 3; p * p <= n; p += 2) {
		while (n % p == 0) {
			PF[p]++;
			n /= p;
		}
	}
	if (n != 1) {
		PF[n]++;
	}
	return PF;
}
int main() {
	cin >> N;
	map<ll, ll> M;
	for (i = 2; i <= N; i++) {
		map<ll, ll> PF;
		primeFactorize(i, PF);
		for (auto x : PF) M[x.first] += x.second;
	}
	ll ans = 1;
	for (auto x : M) (ans *= x.second + 1) %= MOD;
	cout << ans;
}

Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "c2.cpp"

int main() {
  ll n;
  cin >> n;
  vl a(n);
  cin >> a;

  sort(all(a));

  ll ans = 0;
  vector<bool> sign(n);
  vl m, p;

  rep(i, n) {
    if (i == 0) {
      sign[i] = 1;
    } else if (i == n-1) {
      sign[i] = 0;
    } else {
      sign[i] = a[i] < 0;
    }
    if (sign[i]) {
      ans += -a[i];
      m.push_back(a[i]);
    } else {
      ans += a[i];
      p.push_back(a[i]);
    }
  }

  cout << ans << el;

  while (p.size() > 1) {
    ll x = m.back();
    ll y = p.back();

    cout << x << " " << y << el;

    p.pop_back();
    m.back() = x-y;
  }

  ll x = p.front();
  while (m.size()) {
    ll y = m.back();
    cout << x << " " << y << el;

    x = x - y;
    m.pop_back();
  }
}


Measured memory_bytes: 3576
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int main()
{
  int n,K;
  scanf("%d%d",&n,&K);
  vector<vector<int> > e(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans=n;
  static int D[2000][2000];
  for(int s=0;s<n;s++){
    int v[2000];
    for(int i=0;i<n;i++){
      v[i]=-1;
    }
    v[s]=0;
    queue<int> Q;
    Q.push(s);
    while(!Q.empty()){
      int i=Q.front();
      Q.pop();
      for(int x=0;x<e[i].size();x++){
	int j=e[i][x];
	if(v[j]==-1){
	  v[j]=v[i]+1;
	  Q.push(j);
	}
      }
    }
    for(int i=0;i<n;i++){
      D[s][i]=v[i];
    }
  }
  for(int s=0;s<n;s++){
    int L[2001]={0};
    for(int i=0;i<n;i++){
      L[D[s][i]]++;
    }
    int a=0;
    for(int i=K/2+1;i<=n;i++){
      a+=L[i];
    }
    if(K%2==1){
      int b=0;
      for(int x=0;x<e[s].size();x++){
	int i=e[s][x];
	int c=0;
	for(int j=0;j<n;j++){
	  if(D[s][j]==K/2+1&&D[s][j]==1+D[i][j]){
	    c++;
	  }
	}
	b=max(b,c);
      }
      a-=b;
    }
    ans=min(ans,a);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 16000
# PROXY

N = int(input())
A = list(input() + input() + input())
counter = 0
time = 0
while counter < N:
    if A[counter] == A[counter + N] and A[counter] == A[counter + N*2]:
        time += 2
        counter += 1
    elif A[counter] == A[counter + N]:
        time += 1
        counter += 1
    elif A[counter] == A[counter + N*2]:
        time += 1
        counter += 1
    elif A[counter + N] == A[counter + N*2]:
        time += 1
        counter += 1
    else:
        time += 0
        counter += 1
print(2*N - time)

Measured memory_bytes: 3064
data = input().split()
N = int(data[0])
Y = int(data[1])

flag = False

for a in range(N + 1):
    if flag == True:
        break
    for b in range(N + 1):
        if flag == True:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

if flag == False:
    print("-1 -1 -1")


Measured memory_bytes: 3060