akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int n,m;
int a[2004], b[2004];

int dp[2004][2004];
int ans[2004][2005];


int32_t main(){
	fastio();
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++) cin >> b[i];
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++) dp[i][0] = 1;
	for(int j = 0; j <= m; j++) dp[0][j] = 1;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			
			dp[i][j]  = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] +mod;
			dp[i][j] %= mod;
			if(a[i] == b[j]) dp[i][j] += dp[i - 1][j - 1], dp[i][j] %= mod;
		}
	}
	cout << dp[n][m];

}

Measured memory_bytes: 34940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 5005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, m;
string o, e;
int main() {
  cin>>o>>e;
  int i = 0;
  int j = 0;
  string ans="";
  while(i < o.size() || j < e.size()) {
  	if (i < o.size()) {
    	ans.push_back(o[i++]);
    }
    if (j < e.size()) {
    	ans.push_back(e[j++]);
    }
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 079
	// https://atcoder.jp/contests/abc079/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		long[] lucas = new long[n+1];
		lucas[0] = 2;
		lucas[1] = 1;
		
		for (int i = 2; i <= n; i++) {
			lucas[i] = lucas[i-1] + lucas[i-2];
		}
		System.out.println(lucas[n]);
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 21076
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>	
#include <utility>
#include <cinttypes>
#include <string>
#include <iostream>
using namespace std;
int main(){
    int n,counter = 0;
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cin >> n;
    vector<string> s;
    s.reserve(n);
    for (int i=0;i<n;i++){
       string tmp;
       cin >> tmp;
       s.push_back(tmp);
       for (int i=0;i<tmp.length()-1;i++){
           if (tmp.substr(i,2) == "AB"){
               counter++;
           }
       }
    }
    int left_b = 0;
    int right_a = 0;
    int left_b_right_a = 0;
    for (int i= 0;i<n;i++){
        if (s[i][0] == 'B'){
            left_b ++;
        }
        if (s[i][s[i].length()-1] == 'A'){
            right_a ++;
        }
        if ((s[i][0] == 'B')&&(s[i][s[i].length()-1] == 'A')){
            left_b_right_a++;
        }
    }
    if ((left_b == right_a)&&(left_b == left_b_right_a)){
        counter += max(left_b-1,0);
    } else {
        counter += min(left_b,right_a);
    }
    printf("%d\n",counter);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
int main()
{
    struct node{
			int a,b,c;
		};
		struct cmp{
			bool operator()(node a, node b){
				return a.a < b.a;
			}
		};
    LL a,b,c;
    while(cin>>a>>b>>c){
            map<node,int,cmp>num;
        node tmp;
        tmp.a=a,tmp.b=b,tmp.c=c;
        num[tmp]=1;
        int ans=0,no=0;
        while(1){
        ans++;
            if(tmp.b%2||tmp.a%2||tmp.c%2)
                bk;
            node t;
            t.a=tmp.b/2+tmp.c/2;
            t.b=tmp.a/2+tmp.c/2;
            t.c=tmp.b/2+tmp.a/2;
            tmp=t;

            if(num[tmp]){
               no=1;
                bk;
                }

        }
        if(no)
            cout<<-1<<endl;
        else
            cout<<ans-1<<endl;




    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=1000005;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 


ll int power(ll int a,ll int b)
{
    ll int ans=1,f=a;
    while(b)
    {
        if(b&1ll) ans=(ans*f)%mod;
        b=b>>1ll;
        f=(f*f)%mod;
    }
    return ans;
}


int pr[mex],fr[mex];
vector<int> dp[mex];
int main()
{
    for(int i=2;i<mex;i++)
    {
        if(pr[i]==0)
        {
        for(int j=i;j<mex;j+=i)
        {
            dp[j].pb(i);
            pr[j]=1;
        }
        }
    }
    int n;
    cin>>n;
    int a[n],an=0,fg=0;
    fo(i,0,n)
    {cin>>a[i];
    fo(j,0,sz(dp[a[i]]))
    fr[dp[a[i]][j]]++;

    an=__gcd(an,a[i]);
    }
    fo(i,2,mex)
    {
        if(fr[i]>1) fg=1;
    }
    if(an!=1) cout<<"not coprime"<<endl;
    else if(fg) cout<<"setwise coprime"<<endl;
    else cout<<"pairwise coprime"<<endl;
  
  

}

Measured memory_bytes: 70644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var x = ReadInts();

            var list = new List<int>();
            for (int p = 1; p <= 100; p++)
            {
                // p で集会
                var cost = 0;
                for (int i = 0; i < n; i++)
                {
                    cost += (x[i] - p) * (x[i] - p);
                }
                list.Add(cost);
            }
            WriteLine(list.Min());
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
function Main(input) {
  input = input.trim();
  var N = parseInt(input, 10);
  var ans = 0;
  t = new Array(N + 1).fill(0);
  for (var i = 0; i <= N; i++) {
    if (i % 2 == 0) continue;
    var bias = i;
    while (true) {
      if (N < bias) break;
      if (bias % 2 == 1) t[bias] += 1;
      bias += i;
    }
  }
  t.map((n) => {
    if (n == 8) {
      ans++;
    }
  });
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9800
stra = input()


def hantei(s):
    for i in range(int(len(s) / 2)):
        if (s[i] != s[len(s) - 1 - i]):
            # print("A")
            return False
        if (int((len(s) + 3) / 2) - 1 + i < len(s) and s[(int((len(s) + 3) / 2)) - 1  + i] != s[len(s) - 1 - i]):
            # print("B")
            return False

    for i in range(int(len(s) / 4)):
        if (s[i] != s[int(len(s)/2) - 1 - i]):
            # print("C")
            return False
    return True


if(hantei(stra)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;
 
priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
const ll mod = 998244353ll;
// const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    assert(n >= r);
    assert(n >= 0);
    assert(r >= 0);
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;
 
ll n,m,num,a,b,c,d,e,q;
 
ll x[100005], y[100005], z[100005];
ll k, ans;
 
void solve(){
    cin >> a >> b >> c >> k;
    if(a >= k){
        p(k);
    }else if(a + b >= k){
        p(a);
    }else{
        p(a - (k - a - b));
    }
    
    return;
}
 
int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}

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

l = 0
r = max(A)
while l + 1 < r:
    m = (l+r)//2
    n = sum([(x-1)//m for x in A])
    if n > K:
        l = m
    else:
        r = m
print(r)

Measured memory_bytes: 220168
function main(input)
{
  var N = parseInt(input[0]);
  var setA = new Set(input[1].split(' '));
  
  if(N == setA.size){
  	console.log('YES');
  }else{
  	console.log('NO');
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))

Measured memory_bytes: 42652
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100025;
const int inf=0x3f3f3f3f;
ll dp[maxn][5];
struct node
{
    ll x,y,z;
}arr[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i) 
	cin>>arr[i].x>>arr[i].y>>arr[i].z;
    dp[1][0]=arr[1].x;
	dp[1][1]=arr[1].y;
	dp[1][2]=arr[1].z;
    for(int i=2;i<=n;++i)
    {
    	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i].x;
	    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i].y;
	    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i].z;
	}
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 9828
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(N)R(M);
  int c=0;
  int n=(N-1)/2;
  int a=1,b=n;//蟾ｮn-1
  while (a<b) {
    std::cout<<a<<" "<<b<<std::endl;
    if(++c==M)return 0;
    a++;b--;
  }

  a=n+1,b=2*n+1;//蟾ｮn
  while (a<b) {
    std::cout<<a<<" "<<b<<std::endl;
    if(++c==M)return 0;
    a++;b--;
  }
  return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,M;
    Scd2(N,M);

    priority_queue<int> p;
    int a;
    Rep(i,N){
        Scd(a);
        p.push(a);
    }

    Rep(i,M){
        a = p.top();
        p.pop();
        a /= 2;
        p.push(a);
    }

    ll ans = 0;
    while( p.size() ) {
        ans += p.top();
        p.pop();
    }

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

    return 0;
}





Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    map<char, int> alph;
    for (int i=0; i<N; i++) {
        if(alph.find(S[i]) != alph.end()){
            alph[S[i]]++;
        }
        else{
            alph.emplace(S[i], 1);
        }
    }
    
    long ans = 1;
    long mod = 1000000007;
    auto begin = alph.begin(), end = alph.end();
    for(auto itr = begin; itr != end; itr++){
        ans *= (long)itr->second + 1;
        ans %= mod;
    }
    ans += mod -1;
    ans %= mod;
    cout << ans << endl;
//
//    vector<pair<int, int>> alph;
//    for(int i=0; i<N; i++){
//        if(mp.find(s[i]) != mp.end()){
//            mp[s[i]]++;
//        }
//        else{
//            mp.emplace(s[i], 1);
//        }
//    }
//    for(int i=0; i<M; i++){
//        if(mp.find(t[i]) != mp.end()){
//            mp[t[i]]--;
//        }
//        else{
//            mp.emplace(t[i], -1);
//        }
//    }
//
//    int ans=0;
//    auto begin = mp.begin(), end = mp.end();
//    for(auto itr = begin; itr != end; itr++){
//        if(itr->second > ans){
//            ans = itr->second;
//        }
//    }
//    cout << ans << endl;
}



Measured memory_bytes: 512
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const A = input[1].map(Number);

  let answer = 0;

  for (let i = 1; i <= N; i++) {
    if (i % 2 !== 0 && A[i - 1] % 2 !== 0) {
      answer += 1;
    }
  }

  return answer;
};

console.log(main(read()));


Measured memory_bytes: 29680
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
vector<li>p;
void dfs(vector<li>v[],li visit[],li s)
{
  visit[s]=1;
  p.push_back(s+1);
  for(auto i=v[s].begin();i!=v[s].end();i++)
  {
    if(!visit[*i])
      dfs(v,visit,*i);
  }
}
int main()
{
fast_io
string s;
cin>>s;
if(s[2]==s[3]&&s[4]==s[5])
cout<<"Yes";
else
cout<<"No";

return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

zeros = 0
ones = 0
S.split('').each do |s|
  zeros += 1 if s == '0'
  ones += 1 if s == '1'
end

puts [zeros, ones].min * 2


Measured memory_bytes: 22828
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
    int n, d;
    std::cin >> n >> d;
    std::cout << ((n - 1) / (2 * d + 1)) + 1;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int lub(int l,int r,int n,int *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<=d[m]?lub(l,m,n,d):lub(m+1,r,n,d);
}
int ub(int l,int r,int n,int *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?ub(l,m,n,d):ub(m+1,r,n,d);
}
void prls(int v,int *ta,int *to,int *nt){
  int i,j;
  for(i=1;i<=v;i++){
    printf("%d:",i);
    for(j=ta[i];j+1;j=nt[j])printf("%d ",to[j]);
    printf("\n");
  }
  printf("\n");
}
  int n,m,s,g,r,t,a,b,l,ta[100010],to[600010],nt[600010],q[600010];
int main(){
  int c[2][100010]={};
  int i,f[100010]={};
  long long ans=0;
  scanf("%d %d %d %d",&n,&m,&s,&g);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[i  ]=ta[to[i+m]=a];
    nt[i+m]=ta[to[i  ]=b];
    ta[a]=i  ;
    ta[b]=i+m;
  }
  q[t=0]=s;
  c[0][0]=0;
  f[s]=1;
  for(r=1;r-t;t++){
    if(q[t]==g)l=c[0][t];//printf("%d %d\n",q[t],c[0][q[t]]);
    for(i=ta[q[t]];i+1;i=nt[i]){//printf("%d ",c[0][q[t]]);
      if(f[to[i]])continue;//printf("%d ",c[0][q[t]]);
      c[0][r]=c[0][t]+1;//printf(":%d %d %d\n",q[t],c[0][r],to[i]);
      f[to[i]]=1;
      q[r++]=to[i];
    }
  }//printf("\n");
  m=r;//printf("%d %d\n",r,l);
  //for(i=0;i<r;i++)printf("%d ",c[0][i]);printf("\n");
  q[t=0]=g;
  f[g]=2;
  for(r=1;r-t;t++){
    ans+=ub(0,m-1,l-2-c[1][t],c[0])-lub(0,m-1,l-2-c[1][t],c[0]);
    //printf("%d %d %d\n",a,c[1][t],q[t]);
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(f[to[i]]-1)continue;
      c[1][r]=c[1][t]+1;
      f[to[i]]=2;
      q[r++]=to[i];
    }
  }
  printf("%lld\n",ans);
  return 0;
}
      

Measured memory_bytes: 7432
kn = list(map(int, input().split()))
a = list(map(int, input().split()))

a.append(kn[0]+a[0])
dist = []
for i in range(1, kn[1]+1):
    dist.append(a[i]-a[i-1])

dist[dist.index(max(dist))] = 0

print(sum(dist))

Measured memory_bytes: 26436
#include <iostream>
#include <cstdio>
#include "bits/stdc++.h"
using namespace std;

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

  int N;
  cin >> N;

  vector<int> H(N);
  for(int i=0; i<N; i++){cin >> H[i];}

  vector<int> dp(N, 0);
  dp[1] = abs(H[1]-H[0]);
  for(int i=2; i<N; i++){
    dp[i] = min(abs(H[i]-H[i-1])+dp[i-1], abs(H[i]-H[i-2])+dp[i-2]);
  }
  cout << dp[N-1] << endl;
  return 0;
}

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


int main() {

    int K , N;
    cin >> K >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    a.push_back(a[0] + K);
    int l = 0;
    for(int i = 0; i < N; i++){
        l = max(l, a[i+1] - a[i] );
    }
    cout << K - l << endl;

    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
ll abs(ll a,ll b){
    return(a>b?a-b:b-a);
}

int main(){
    int n;
    cin >> n;
    
    vl a(n);
    rp(i,n){
        cin >> a[i];
    }
    vl s(n);
    s[0]=a[0];
    lrep(i,1,n-1){
        s[i] = s[i-1] + a[i];
    }
    ll min = LLONG_MAX;
    rp(i,n-1){
        if(abs(s[i],s[n-1]-s[i])<min){
            min = abs(s[i],s[n-1]-s[i]);
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
n, m = map(int,input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        count = 0
        for k in range(m):
            for l in range(m):
                if b[k][l] == a[i+k][j+l]:
                    count += 1
        if count == m * m:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
    int A[100][100];
    int B[100];
    int C[100] ={0};
    int n,m,i,j;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
        scanf("%d",&A[i][j]);
        }
    }
   for(j=0;j<m;j++) scanf("%d",&B[j]);
    for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) {
      C[i] += A[i][j] * B[j];
    }
    printf("%d\n",C[i]);
  }
   return 0; 
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;


int main(int argc, char **argv)
{
	long double a, b, c; cin >> a >> b >> c;
	std::cout << ((a + 2*sqrt(a)*sqrt(b) + b < c)? "Yes" : "No")<< std::endl;
}

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

int main() {
  int N;
  cin >> N;
  
  double temp, ans;
  ans = 0;
  for(int i=0; i<N; i++){
	cin >> temp;
    ans += 1/temp;
  }
  
  
  printf("%.6f",1/ans);
  return 0;
}


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

int main(){ 
  int N, M;
  cin >> N >> M;
  vector<int64_t> P(100010), Y(100010);
  vector<vector<int64_t>> yd(100010, vector<int64_t>(0));
  
  rep(i, M){
    cin >> P.at(i) >> Y.at(i);
    yd.at(P.at(i)).push_back(Y.at(i));
  }
  rep(i, N) sort(yd.at(i+1).begin(), yd.at(i+1).end());
  rep(i, M){
    
    int64_t ans = 1000000000000;
    ans += P.at(i) * 1000000;
    ans += lower_bound(yd.at(P.at(i)).begin(), yd.at(P.at(i)).end(), Y.at(i)) - yd.at(P.at(i)).begin() + 1;
    string ans2 = to_string(ans);
    cout << ans2.substr(1) << endl;
    
    /*
    int ans = P.at(i) * 1000000 + lower_bound(yd.at(P.at(i)).begin(), yd.at(P.at(i)).end(), Y.at(i)) - yd.at(P.at(i)).begin() + 1;
    string ans2 = "00000" + to_string(ans);
    int ss = ans2.size();
    cout << ans2.substr(ss - 12) << endl;
    */
  }
}

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

int main() {
    int H, W, i, j;
    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {return 0;}
        for (i = 0; i < H; ++i) {
            for (j = 0; j < W; ++j) {
                if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int S[200020], X[200020];
    rep(i,n) {
        int a;
        cin >> a;
        S[i+1] = S[i] + a;
        X[i+1] = X[i] ^ a;
    }
    int l = 0, r = 1;
    ll ans = 0;
    while(r<=n){
        while(r<=n && (S[r] - S[l] == (X[r] ^ X[l]))) {
            ans += r - l;
            r++;
        }
        l++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
typedef long long ll;
using namespace std;
ll read(){
	ll x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		  if (ch=='-') w=-1;
		  ch=getchar();
	}
	while (ch<='9' && ch>='0'){
		  x=(x<<1)+(x<<3)+ch-'0';
		  ch=getchar();
	}
	return x*w;
}
ll m,a[100005];
int n,ans;
int main()
{
   n=read();m=read();
    for (int i=1;i<=n;i++)
        a[i]=read();
    sort(a+1,a+n+1);
    for (int i=1;i<n;i++)
        if (m>=a[i]) m-=a[i],ans++;
    if (m==a[n]) ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


x, y = map(int, input().split())
mod = 10**9+7

if (-x+2*y)>= 0 and (-x+2*y)%3 == 0 and  (2*x-y)>= 0 and (2*x-y)%3 == 0:
    a = (-x+2*y)//3
    b = (2*x-y)//3
    print(cmb1(a+b, a, mod))
else:
    print(0)


Measured memory_bytes: 127584
# coding: utf-8
# Here your code !

def func():
    try:
        line=input().rstrip()
        list=line.split(" ")
        a=int(list[0])
        b=int(list[1])
        c=int(list[2])
    except:
        print("input error")
        return -1
    
    if((a<b) and (b<c)):
        print("Yes")
    else:
        print("No")

func()

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 3010
const int MOD = 1000000007;

int v[maxn];
int dp[maxn][maxn];

int solve(int l, int r) {
    if (l > r)return 0;
    int &ans = dp[l][r];
    if (ans != -1)return ans;
    ans = v[l] - solve(l + 1, r);
    ans = max(ans, v[r] - solve(l, r - 1));
    return ans;
}

void solve() {
    memset(dp, -1, sizeof dp);
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    cout << solve(0, n - 1) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    while (t--)
        solve();
    return 0;
}



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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int inp[N];


  int sum = 0;
  int before = 0;
  for (int i=0; i<N; i++) 
  {
    int tmp;
    cin >> tmp;
    sum += abs(tmp - before);

    before = tmp;
    inp[i]  = tmp;
  }


  sum += abs(before);



//  int before = inp[0];
//  int sum = 0;
//  int afterbreakfirstormax = 0;

//  for (int i=0; i<N; i++) 
//  {
//    if ((inp[i] * before)<=0) {
//      sum += abs(before)*2;
//      before = inp[i];
//      afterbreakfirstormax=1;
//
//    } 
//    
//    else {
//      if (inp[i] > 0) {
//        if (before < inp[i])
//          afterbreakfirstormax=1;
//        else
//          afterbreakfirstormax=0;
//
//        before = max(before, inp[i]);
//      } else {
//
//        if (before > inp[i])
//          afterbreakfirstormax=1;
//        else
//          afterbreakfirstormax=0;
//
//        before = min(before, inp[i]);
//      }
//    }
//
//
//    if (i ==0)
//      afterbreakfirstormax=1;
//
//  }


//  if (afterbreakfirstormax)
//    sum += abs(before)*2;

  //cout << "sum: " << sum << endl;
  // output
  for (int i=0; i<N; i++) 
  {
    int calcans = sum;
    if (i==0) {
      calcans -= abs(inp[0] - inp[1]);
      calcans -= abs(inp[0]);
      calcans += abs(0-inp[1]);

    } else if (i==N-1) {
      calcans -= abs(inp[N-1] - inp[N-2]);
      calcans -= abs(inp[N-1]);
      calcans += abs(0-inp[N-2]);

    } else {
      calcans =   sum - ( abs(inp[i]- inp[i-1]) + abs(inp[i]- inp[i+1]) );
      calcans +=  abs(inp[i-1]- inp[i+1]);
    }
    cout << calcans << endl;
    
  }
    
  
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 5005
#define v_n 5005
#define LL long long
#define e_n 5000005
#define MOD 1000000007
#define eps 0.000000001
#define Blen 32
using namespace std;
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	int N, K;
	cin >> N >> K;
	double ans =0;
	up(i, 1, N)
	{
		LL v = i;
		double cur = 1.0;
		while (v < K)
		{
			cur *= 0.5;
			v =  v* 2;
		}
		ans += cur;
	}
	printf("%.12lf\n",  ans / N);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int town_dist[100001] = {0};
	int total = 0;
	int current = 0;
	int n, m;
	int i;

	scanf("%d %d", &n, &m);
	for (i = 1; i < n; i++){
		int dist;
		scanf("%d", &dist);

		town_dist[i] = town_dist[i - 1] + dist;
	}
	for (i = 0; i < m; i++){
		int len;
		scanf("%d", &len);
		total += fabs(town_dist[current + len] - town_dist[current]);
		total %= 100000;
		current = current + len;
	}
	printf("%d\n", total);

	return (0);
}

Measured memory_bytes: 992
if __name__ == '__main__':
    opcode = []                 # ?????????????¨???¶??¨
    operand = []                # ?????´????¢??????????????¨???¶??¨

    # ??????????????\???
    while True:
        data = input()
        if data == '=':
            break
        elif data == '+' or data == '-' or data == '*' or data == '/':
            opcode.append(data)
        else:
            if len(operand) == 0:
                operand.append(int(data))
            else:
                op = opcode.pop()
                operand1 = operand.pop()
                operand2 = int(data)
                if op == '+':
                    operand.append(operand1 + operand2)
                elif op == '-':
                    operand.append(operand1 - operand2)
                elif op == '*':
                    operand.append(operand1 * operand2)
                elif op == '/':
                    operand.append(operand1 // operand2)

    # ???????????¨???
    print('{0}'.format(operand.pop()))

Measured memory_bytes: 7704
n, k = map(int, input().split())

s = 0
cnt = [2**20 if 1 <= i <= n else 0 for i in range(100002)]
for i in range(1, k):
    if 2 * i < k:
       cnt[2 * i] += cnt[i] // 2
       cnt[0] += cnt[i] // 2
       cnt[i] = 0
    else:
       cnt[-1] += cnt[i] // 2
       cnt[0] += cnt[i] // 2
       cnt[i] = 0
ans = 1.0 - cnt[0] / (n * 2**20)
print(ans)

Measured memory_bytes: 45424
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

ll h[110000];
int main(){
  ll n;
  cin>>n;
  ll tmp=0,ans=0;
  rep(i,0,n){cin>>h[i];}
  rep(i,0,n-1){
    if(h[i]>=h[i+1])tmp++;
    else {ans=max(ans,tmp);tmp=0;}
  }
  ans=max(ans,tmp);
  cout<<ans;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    if(t[pos]!=-1):
        return t[pos]
    t[pos]=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return t[pos]
n=int(input())
l=list(map(int,input().split()))
global t
t=[-1]*(n+1)
print(solve(n,l,1))

Measured memory_bytes: 104184
#include<stdio.h>

int main(){

	int a,b,c,d,i,flag=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);

	if(a==9&&b==7&&c==4&&d==1){
		flag=1;
	}
	if(a==9&&b==7&&c==1&&d==4){
		flag=1;
	}
	if(a==9&&b==4&&c==7&&d==1){
		flag=1;
	}
	if(a==9&&b==4&&c==1&&d==7){
		flag=1;
	}
	if(a==9&&b==1&&c==7&&d==4){
		flag=1;
	}
	if(a==9&&b==1&&c==4&&d==7){
		flag=1;
	}
	if(a==7&&b==9&&c==4&&d==1){
		flag=1;
	}
	if(a==7&&b==9&&c==1&&d==4){
		flag=1;
	}
	if(a==7&&b==4&&c==9&&d==1){
		flag=1;
	}
	if(a==7&&b==4&&c==1&&d==9){
		flag=1;
	}
	if(a==7&&b==1&&c==9&&d==4){
		flag=1;
	}
	if(a==7&&b==1&&c==4&&d==9){
		flag=1;
	}
	if(a==4&&b==9&&c==7&&d==1){
		flag=1;
	}
	if(a==4&&b==9&&c==1&&d==7){
		flag=1;
	}
	if(a==4&&b==7&&c==9&&d==1){
		flag=1;
	}
	if(a==4&&b==7&&c==1&&d==9){
		flag=1;
	}
	if(a==4&&b==1&&c==9&&d==7){
		flag=1;
	}
	if(a==4&&b==1&&c==7&&d==9){
		flag=1;
	}
	if(a==1&&b==9&&c==7&&d==4){
		flag=1;
	}
	if(a==1&&b==9&&c==4&&d==7){
		flag=1;
	}
	if(a==1&&b==7&&c==9&&d==4){
		flag=1;
	}
	if(a==1&&b==7&&c==4&&d==9){
		flag=1;
	}
	if(a==1&&b==4&&c==9&&d==7){
		flag=1;
	}
	if(a==1&&b==4&&c==7&&d==9){
		flag=1;
	}

	if(flag==0){
		printf("NO\n");
	}
	else{
		printf("YES\n");
	}


}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

std::vector<ll> divisor(ll n) {
    std::vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    RSORT(ret);
    return (ret);
}

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

    int N, M;
    std::cin >> N >> M;

    auto div_list = divisor(M);
    for(const auto& v : div_list) {
        if(v <= M / N) {
            std::cout << v << std::endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
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 V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

vector<ll> vs;
vector<vector<ll>> dp;
int N,K;

ll solve(int f, int b) {
  if (dp[f][b] != -1) return dp[f][b];

  int k = K - f - (N - b);
  // debug(k);
  ll ans=0;
  if (k == 0) {
    ans = max(accumulate(vs.begin(), vs.begin()+f,0), accumulate(vs.begin() + b, vs.end(), 0));
  } else {
    if (f + 1 <= b) {
      ans = max(ans, solve(f + 1, b));
    }
    if (f <= b-1) {
      ans = max(ans, solve(f, b - 1));
    }
    if (K-k > 0) {
      vector<ll> vt(K-k);
      copy(vs.begin(), vs.begin()+f, vt.begin());
      copy(vs.begin()+b, vs.end(), vt.begin()+f);
      debug(f,b,vt);
      sort(vt.begin(), vt.end());
      auto it = vt.begin();
      while (*it < 0 && k > 0 && it != vt.end()) {
        it++; k--;
      }
      debug(k,(*it),vt);
      ll ans3 = accumulate(it, vt.end(), 0);
      ans = max(ans, ans3);
    }
  }

  dp[f][b] = ans;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> N >> K;

  vs = make_v<ll>(N);
  dp = make_v<ll>(N+1, N+1);
  fill_v(dp, -1);

  REP(i,N) {
    ll v;
    cin >> v;
    vs[i] = v;
  }
  debug(N,K,vs);
  ll ans = solve(0,N);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	ll a, c, b;
	cin >> a >> b >> c;

	if((a < c && c < b)||(b < c && c < a)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
vector<int> G[100005];
std::vector<P> tree[100010];
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
ll i,j,k,l,ii,jj;
ll n,m;
string s,a[55555];
ll h,w,x,y,ans=0,sum;
ll ite;
int main(){
	cin>>s;
	cin>>ii;
	n=s.length();
	for(i=1;i<=5;i++){
		for(k=0;k+i<=n;k++){
			a[l]=s.substr(k,i);
			l++;
		}
	}
	sort(a,a+l);
	unique(a,a+l);
	p(a[ii-1]);
	system ("pause");
	return 0;
}

Measured memory_bytes: 6776
#include<stdio.h>
int main(void){
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if((0<=x-r&&x+r<=w)&&(0<=y-r&&y+r<=h)){

printf("Yes\n");

}else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 584
/*input
1 100000
1
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define input(str) freopen(str,"r",stdin);
#define output(str) freopen(str,"w",stdout);
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF  3e16+1
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld\n",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define modd 1000000007
#define len(x) x.size()
#define all(v) (v.begin(),v.end())
#define ll int
#define pi 3.1415926535897932384626
#define ld double
const int N =6e5+5;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
int powmod(int base,int exp,int mod)
{
	int res=1LL;
	while(exp>0)
	{
		if(exp&1LL)
			res=(res*base)%mod;
		exp/=2LL;
		base=(base*base)%mod;
	}
	return res%mod;
}
int dp[1000001];
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	rep(i,n)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	rep(i,n)
	{
		dp[a[i]]=1;
	}
	for(int i=1;i<a[0];i++)
	{
		dp[i]=2;
	}
	for(int i=1;i<=k;i++)
	{
		if(dp[i]==1||dp[i]==2)
			continue;
		else
		{
		
			int flag=0;
			for(int j=0;j<n;j++)
			{
				if(a[j]>=i)
				{
					break;
				}
				else
				{
					if(dp[i-a[j]]==2)
					{
						flag=1;
						break;
					}
				}
			}
			if(flag)
				dp[i]=1;
			else
				dp[i]=2;
		}
	}
	if(dp[k]==1)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
 
char X[1001], Y[1001];
 
int LCS_Length(){
  int i, j;
  int m = strlen(X);
  int n = strlen(Y);
  int c[m + 1][n + 1];
 
  for(i = 1; i <= m ;i++) c[i][0] = 0;
  for(j = 0; j<= n ;j++) c[0][j] = 0;
   
  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(X[i - 1] == Y[j - 1]) c[i][j] = c[i - 1][j - 1] + 1;

      else if(c[i - 1][j] >= c[i][j - 1]) c[i][j] = c[i - 1][j];

      else c[i][j] = c[i][j - 1];
    }
  }

  return c[m][n];
}

int main(){
  int i, q;

  scanf("%d",&q);

  for(i = 0; i < q; i++){
    scanf("%s%s", X, Y);

    printf("%d\n",LCS_Length());
  }

  return 0;
}

Measured memory_bytes: 4512
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
match = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    for j in a:
        if i - match[j] < 0: continue
        if dp[i-match[j]] == -1: continue
        dp[i] = max(dp[i], dp[i-match[j]]*10+j)
# print(dp)
print(dp[n])

Measured memory_bytes: 14388
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

int main(int argc, const char * argv[]) {
  ll h, w, n;
  cin >> h >> w >> n;
  
  vector<ll> cnt(10);
  set<pair<int, int>> pos, check;
  for (int i = 0; i < n; i++) {
    int r, c;
    cin >> r >> c;
    pos.insert({r, c});
    
    for (int y = max(1, r - 2); y <= r; y++) {
      for (int x = max(1, c - 2); x <= c; x++) {
        if (y + 2 <= h && x + 2 <= w) {
          check.insert({y, x});
        }
      }
    }
  }
  
  for (auto &p : check) {
    int num = 0;
    for (int r = p.first; r <= p.first + 2; r++) {
      for (int c = p.second; c <= p.second + 2; c++) {
        if (pos.count({r, c})) {
          num++;
        }
      }
    }
    cnt[num]++;
  }
  
  cout << (h - 2) * (w - 2) - accumulate(cnt.begin() + 1, cnt.end(), 0ll) << endl;
  for (int i = 1; i < 10; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	ll x;
	cin>>x;
	ll ans = 0;
	ans += 1000*(x/500);
	x %= 500;
	ans += 5*(x/5);
	cout<<ans<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool visit[100];
int finish_time[100];
int find_time[100];
int t;
vector<int> E[100];
void dfs(int u){
  visit[u] = true;
  find_time[u] = ++t;
  for(int v : E[u]) if(!visit[v]) dfs(v);
  finish_time[u] = ++t;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    u--;
    rep(j,k){
      int v;
      cin >> v;
      v--;
      E[u].push_back(v);
    }
  }
  rep(i,n) if(!visit[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << find_time[i] << " " << finish_time[i] << endl;
  }
  return 0;
}



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


int n;

void dfs(int k,string t){
  int i;
  
  if (t.size()==n){
    cout << t << endl;
    return;
  }
  
  for (i=0;i<=k;i++){
    char next='a'+i;
    if (i==k) dfs(k+1,t+next);
    else dfs(k,t+next);
  }
  
}


int main(void){
  
  cin >> n;
  
  dfs(0,"");
  
  return 0;
}

Measured memory_bytes: 1536