akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
using p = pair<ll,ll>;

void a(){
    ll h,a;
    cin >> h >> a;
    cout << (h%a==0? h/a:h/a+1);
}

void b(){
    ll h,n;
    cin >> h >> n;
    auto a = v(n,0);
    for(ll i=0;i<n;i++) cin >> a[i];
    ll sum = accumulate(a.begin(),a.end(),0);
    cout << (sum>=h?"Yes":"No");
}

int main(){
    b();
    return 0;
}

Measured memory_bytes: 1024
// C - Knot Puzzle

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int a[100000];

int main() {
	int N, L;
	cin >> N >> L;

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

	int max_pair_len = 0;
	int pair_knot;
	for (int i=1; i<N; i++) {
		if (a[i-1] + a[i] > max_pair_len) {
			max_pair_len = a[i-1] + a[i];
			pair_knot = i;
		}
	}

	if (max_pair_len < L) {
		cout << "Impossible" << endl;
		return 0;
	}

	vector<int> ans;

	for (int i=1; i<pair_knot; i++) {
		ans.push_back(i);
	}

	for (int i=N-1; i>pair_knot; i--) {
		ans.push_back(i);
	}

	ans.push_back(pair_knot);

	cout << "Possible" << endl;

	for (int a : ans) {
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 4272
import numpy as np
N=list(range(1,int(input())+1))
a=np.asarray(N,dtype='int64')
b=a%3
c=a%5
d=np.array([a,b,c])
d=np.delete(d, np.where(d==0)[1], axis=1)
print(np.sum(d[0]))

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

int main(){
  ll k;
  cin >> k;
  ll st = k/50;
  ll st2 = k%50;
  vector<ll> ans(50,st+49);
  for(int i=0; i<st2; ++i){
    for(int j=0; j<50; ++j){
      if(i==j) ans[j] += 50;
      else --ans[j];
    }
  }
  cout << 50 << endl;
  for(int i=0; i<50; ++i){
    if(i!=49) cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, k;
  scanf("%d%d", &n, &k);
  char s[n + 1];
  scanf("%s", s);
  if (s[0] == '1') k++;
  int l = 0;
  int r = 0;
  int ans = r - l;
  while (r < n) {
    while (k > 0) {
      while (r < n && s[r] == '0') r++;
      while (r < n && s[r] == '1') r++;
      k--;
    }
    if (ans < r - l) ans = r - l;
    while (l < n && s[l] == '1') l++;
    while (l < n && s[l] == '0') l++;
    k++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

class DisjointSet {
   private:
    vector<int> rank, parent;

   public:
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        rep(i, size) { makeSet(i); }
    }

    void makeSet(int x) {
        parent[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y) { return findSet(x) == findSet(y); }

    void unite(int x, int y) { link(findSet(x), findSet(y)); }

    void link(int x, int y) {
        if (x == y) {
            return;
        }
        if (rank[x] > rank[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
    int findSet(int x) {
        if (x != parent[x]) {
            parent[x] = findSet(parent[x]);
        }
        return parent[x];
    }
};
int n, q;

int main() {
    cin >> n >> q;
    DisjointSet ds(n);
    rep(i, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            ds.unite(u, v);
        } else {
            cout << ds.same(u, v) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4732
' Imports System.Collections.Generic
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim N As Integer= Console.ReadLine()
        Console.WriteLine((1000 - N Mod 1000) Mod 1000)
        Return
    End Sub
End Class

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

int main(){
  int X,N;
  cin>>X>>N;
  vector<bool> p(101,false);
  for(int i=0;i<N;++i){
    int n;
    cin>>n;
    p[n]=true;
  }

  int comp=100000;
  int ans=-200;
  for(int i=-200;i<=200;++i){
    if(i<=0){
      if(comp>(int)abs(X-i)){
        ans=i;
        comp=(int)abs(X-i);
      }
    }
    else if(!p[i]){
      if(comp>(int)abs(X-i)){
        ans=i;
        comp=(int)abs(X-i);
      }
    }
  }

  cout<<ans<<endl;
}


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

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

    int i = S.at(6) - '0';
    int j = S.at(5) - '0';
    if( i > 4 ) {
        cout << "TBD" << endl;
    } else {
        if( j == 1 ) {
            cout << "TBD" << endl;
        } else {
            cout << "Heisei" << endl;
        }
    }
}

Measured memory_bytes: 256
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 1000000007
#define inf 1000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int c=0;
void dfs(int s,vector<int>adj[],int vis[])
{
  vis[s]=1;
  for(auto x:adj[s])
  {
    if(vis[x]==0)
    {
      c++;
      dfs(x,adj,vis);
    }
  }
}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
   int n,m,a,b,max1=0;cin>>n>>m;int vis[n+1];mem(vis,0);vector<int>adj[n+1];
   f(m)
   {
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
   }
   for(int i=1;i<=n;i++)
   {
    c=1;
    if(vis[i]==0)
    {
      dfs(i,adj,vis);
      max1=max(max1,c);
      
    }
   }
   cout<<max1; 
}


Measured memory_bytes: 24700
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  rep(i,N) cin >> c[i];
  sort(all(a));
  sort(all(c));
  ll ans=0;
  rep(i,N){
    ll x=lower_bound(a.begin(), a.end(), b[i])-a.begin();
    ll y=upper_bound(c.begin(), c.end(), b[i])-c.begin();
    ans+=x*(N-y);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
    int a, b;
    char op;

    while (1) {
        cin >> a >> op >> b;
        if (op == '+') cout << a + b << endl;
        else if (op == '-') cout << a - b << endl;
        else if (op == '*') cout << a * b << endl;
        else if (op == '/') cout << a / b << endl;
        else break;
    }

    return 0;
}


Measured memory_bytes: 3092
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

n=int(input())
t=[int(input()) for i in range(n)]

LCM=t[0]
for i in range(1,n):
    LCM=lcm(LCM,t[i])

print(LCM)

Measured memory_bytes: 9120
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	multiset<pii>se;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
		se.insert(make_pair(z, i % 2));
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < num; i++)
	{
		multiset<pii>::iterator it = se.find(make_pair(v[i], i % 2));
		if (it == se.end())ans++;
		else se.erase(it);
	}
	printf("%d\n", ans / 2);
}

Measured memory_bytes: 5368
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    map<string,int> st;

    while(n-->0)
    {
        string s;
        cin>>s;
        st[s]++;
    }
    for(auto x:{"AC","WA","TLE","RE"})
        cout<<x<<" x "<<st[x]<<'\n';

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3668
#include<iostream>
using namespace std;
int main(void){

	int d;
	cin>>d;
	if(d==22)cout<<"Christmas Eve Eve Eve"<<endl;
	if(d==23)cout<<"Christmas Eve Eve"<<endl;
	if(d==24)cout<<"Christmas Eve"<<endl;
	if(d==25)cout<<"Christmas"<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(b-a==c-b){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
      

  }
  

  
}


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

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  
  for(auto& e : A)
  {
    cin >> e;
  }
  
  vector<bool> dp(K + 1);
  
  for(int i = 0; i <= K; ++i)
  {
    bool result{false};
    for(const auto e : A)
    {
      if(e <= i and not dp[i - e])
      {
        result = true;
        break;
      }
    }
    dp[i] = result;
  }
  
  cout << (dp[K] ? "First" : "Second") << "\n";
  
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc170/tasks/abc170_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int X, N;
    cin >> X >> N;
    bitset<10000> bt;
    REP(i, N) {
        int t;
        cin >> t;
        bt.set(t);
    }
    if (N == 0) {
        cout << X << endl;
        return;
    }
    int ans = 0, diff = 1e9;
    REP(i, 102) {
        if (!bt[i] && abs(X - i) < diff) {
            ans = i;
            diff = abs(X - i);
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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


int main(void){
  int n,i;
  string s;
  
  cin >> s;
  n=s.size();
  
  for (i=0;i<n;i+=2){
    if (n%2==1 || s[i]!='h' || s[i+1]!='i'){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    stack<char> st{};
    rep(i, N) {
        int c = S[i];
        if (st.empty()) {
            st.push(c);
        } else {
            if (st.top() == 'S') {
                if (c == 'S')
                    st.push(c);
                else
                    st.pop();
            } else {
                st.push(c);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m) 
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}
	
	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };




const int N = 2e6 + 30;
const int mod = 1000000007;

string s;
int pat[N], l[N], r[N];	
int sm;
int main()
{
	fastio;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'R') sm = i;
		r[i] = sm;
	}
	for (int i = s.length() - 1; i >= 0; i--)
	{
		if (s[i] == 'L') sm = i;
		l[i] = sm;
	}
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'R')
		{
			if ((l[i] - i) % 2) pat[l[i] - 1]++;
			else pat[l[i]]++;
		}
		else
		{
			if ((r[i] - i) % 2) pat[r[i] + 1]++;
			else pat[r[i]]++;
		}
	}
	for (int i = 0; i < s.length(); i++)
	{
		cout << pat[i] << " ";
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int cp = n;
  int sum=0;
  while(cp){
    sum += cp%10;
    cp /= 10;
  }
  if(n%sum)cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> v(N); rep(i, N){cin >> v.at(i);}
    sort(v.begin(), v.end());
    double ans = (double)(v.at(0) + v.at(1)) / 2.0;
    if (v.size() >= 3){
        rep(i, N-2){
            ans = (ans + v.at(i+2)) / 2.0;
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 384
#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 n, m, ans = 0;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n, true);
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (h[a] <= h[b]) ok[a] = false;
        if (h[b] <= h[a]) ok[b] = false;
    }
    
    for (int i = 0; i < n; i++)
    {
        if(ok[i]) ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string> 
#include <math.h>
using namespace std;
 int main() {
	 
	 int a;
	 int X;
	 int x;
	 int ans = 0;
	 cin >> X;
	 x = int(sqrt(X));

	 for (int i = 1; i <= x; i++) {
		 for (int j = 2; j <= 10; j++) {
			 
			 a = int(pow(i, j));
			 if (a <= X && a >= ans)
				 ans = a;
		 }
	 }
	 
	 cout << ans << endl;

	 return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	
	int N,T;
	cin>>N>>T;
	int ans=-1,val=1e6;
	for(int i=0;i<N;i++){
		int c,t;
		cin>>c>>t;
		if(t>T){
			continue;
		}
		if(c<val){
			ans=c;
			val=c;
		}
	}
	if(ans==-1){
		cout<<"TLE"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct ee
{
	int x,y;
}a[121],b[121];
bool f[121];
int n,p=1,len=1,ans;
bool mycmp(ee q,ee w)
{
	return q.x<w.x;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i].x>>a[i].y;
	for(int i=1;i<=n;i++)
	cin>>b[i].x>>b[i].y;
	sort(a+1,a+1+n,mycmp);
	sort(b+1,b+1+n,mycmp);
	for(int i=n;i>=1;i--)
	{
		int maxx=10000,t=0;
		for(int j=n;j>=1;j--)
		{
		if(a[i].x>b[j].x) break;
		if(!f[j]&&a[i].y<b[j].y) 
		{
		if(b[j].y<=maxx) maxx=b[j].y,t=j;
		}
		}
	    if(t!=0) f[t]=1,ans++;
	}
	
	/*while(1)
	{
		if(p>n||len>n) break;
		
		if(a[p].x<b[len].x&&a[p].y<b[len].y) {ans++;p++;len++;continue;}
		if(a[p].x>b[) len++;
	}*/
	cout<<ans;
	return 0;
}

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

using namespace std;

void dfs(int v,vector<vector<int>>& vertex, int d[], int f[]);

int cnt = 1;

int main(){
    int n;
    cin >> n;
    int num;
    int tmp2;
    int d[n] = {};
    int f[n] = {};
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2-1);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    dfs(0, vertex, d, f);
    for(int i=0;i<n;i++){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " <<  d[i] << " " << f[i] << endl;
    }
    return 0;
}

void dfs(int v, vector<vector<int>>& vertex, int d[], int f[]){
    d[v] = cnt++;
    for(int i : vertex[v]){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    f[v] = cnt++;
}


Measured memory_bytes: 3148
#include "bits/stdc++.h"

int main()
{
	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
	}
	std::vector<int> dp(n, std::numeric_limits<int>::max());
	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 1; j <= k && i + j < n; ++j)
		{
			dp[i + j] = std::min(dp[i + j], abs(a[i + j] - a[i]) + dp[i]);
		}
	}
	std::cout << dp[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 4048
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Runtime.InteropServices.ComTypes;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static long H;
    static long W;
    static long K;
    static string[] map;
    static long[][] ans;
    static void Main(string[] args)
    {
        var HWK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        H = HWK[0];
        W = HWK[1];
        K = HWK[2];
        map = new string[H];
        ans = new long[H][];
        for (int i = 0; i < H; i++)
        {
            ans[i] = new long[W];
            map[i] = Console.ReadLine();
        }
        Solve();

        for (int i = 0; i < W; i++)
        {
            var now = H - 1;
            while(ans[now][i] == 0)
            {
                now--;
            }

            for (; now+1 < H; now++)
            {
                ans[now + 1][i] = ans[now][i];
            }
        }

        for (int i = 0; i < H; i++)
        {
            Console.WriteLine(String.Join(" ",ans[i]));
        }
    }

    static void Solve()
    {
        var count = 0;
        var cum = 0;
        for (int i = 0; i < H; i++)
        {
            var fir = false;
            for (int j = 0; j < W; j++)
            {
                if(map[i][j] == '#')
                {
                    fir = true;
                    break;
                }
            }

            if (!fir)
            {
                cum++;
                continue;
            }

            for (int j = 0; j < W; j++)
            {
                if(j == 0)
                {
                    count++;
                    
                    for (int k = 0; k <= cum; k++)
                    {
                        ans[i - k][j] = count;
                    }
                }
                else if(map[i][j] == '.')
                {
                    for (int k = 0; k <= cum; k++)
                    {
                        ans[i - k][j]  = count;
                    }
                }
                else if(map[i][j] == '#')
                {
                    if (fir)
                    {
                        for (int k = 0; k <= cum; k++)
                        {
                            ans[i - k][j] = count;
                        }
                    }
                    else
                    {
                        count++;
                        for (int k = 0; k <= cum; k++)
                        {
                            ans[i - k][j] = count;
                        }
                    }
                    
                }

                if (map[i][j] == '#')
                {
                    fir = false;
                }
            }
            cum = 0;
        }
    }



}


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

using namespace std;

typedef pair<int, int> Pi;
typedef pair<int, Pi> Pii;

struct edge{
  int to, dist, risk;
  edge(){}
  edge(int to, int dist, int risk):to(to), dist(dist), risk(risk){}
};

const int inf = 1 << 30;

vector< vector<edge> > G(110);
int minDied[110][110];

int N, M, L;

int dijkstra()
{
  fill(minDied[0], minDied[110], inf);
  priority_queue<Pii, vector<Pii>, greater<Pii> > que;
  que.push(Pii(0, Pi(0, L)));
  minDied[0][L] = 0;
  while(!que.empty()){
    Pii p = que.top(); que.pop();
    int die = p.first, now = p.second.first, bdg = p.second.second;
    if(now == N-1) return die;
    for(int i = 0; i < G[now].size(); i++){
      edge e = G[now][i];
      if(bdg >= e.dist && minDied[e.to][bdg - e.dist] > die){
	que.push(Pii(die, Pi(e.to, bdg - e.dist)));
	minDied[e.to][bdg - e.dist] = die;
      }
      if(minDied[e.to][bdg] > die + e.risk){
	que.push(Pii(die + e.risk, Pi(e.to, bdg)));
	minDied[e.to][bdg] = die + e.risk;
      }
    }
  }
  return -1;
}

int main()
{
  while(cin >> N >> M >> L, N || M || L){
    G.resize(N);
    for(int i = 0; i < M; i++){
      int A, B, D, E;
      cin >> A >> B >> D >> E;
      --A, --B;
      G[A].push_back(edge(B, D, E));
      G[B].push_back(edge(A, D, E));
    }
    cout << dijkstra() << endl;
    G.clear();
  }
  return 0;
}

Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N;
	cin >> N;
	if(N%2 == 0){
		cout << N*(N-1)/2 - N/2 << endl;
		FOR(i,1,N+1)FOR(j,1,N+1){
			if(i >= j)continue;
			if(i+j == 1+N)continue;
			cout << i << ' ' << j << endl;
		}
		return 0;
	}
	vector<pair<int,int>> ans;
	FOR(i,1,N+1){
		FOR(j,1,N+1){
			if(i >= j)continue;
			if(i+j == N)continue;
			ans.pb(make_pair(i,j));
		}
	}
	cout << ans.size() << endl;
	for(auto p:ans)cout << p.first << ' ' << p.second << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

import math

def main():
    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    assert len(an) == n
    mi = min(an)
    imin = []
    for i in range(n):
        if an[i] == mi:
            imin.append(i)

    print(math.ceil((n - 1) / (k - 1)))

main()


Measured memory_bytes: 13812
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {
    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        var n = ReadLib.ReadAsInt();
        var s = Console.ReadLine();

        var x = 0;
        var max = 0;

        foreach (var c in s) {
            if (c == 'I') {
                x++;
                if (max < x) {
                    max = x;
                }
            } else {
                x--;
            }
        }
        
        Console.WriteLine(max);
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion

    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static long[] ReadAsLongArray() {
        return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static ulong[] ReadAsULongArray() {
        return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }

    public static int[][] ReadNTimesAsIntArray(int n) {
        return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray();
    }

}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

const int MAXA = 1e7;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	vector<bool> dp (MAXA, true);
	set<int> vals; 
	map<int, int> occ;
	F0R(i, N) {
		vals.insert(arr[i]);
		occ[arr[i]]++;
	}
	
	for (int x : vals) {
		for (int i = 2; x * i <= MAXA; ++i) {
			dp[x*i] = false;
		}
	}

	int ans = 0;
	for (int x : vals) {
		if (dp[x] == true && occ[x] == 1) ++ans;
	}
	print(ans);
}

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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

#define int ll
const int N = 1e5+7;

int n, X, start;

int b[N];
int l[N];
int u[N];

VPII vec;

int pref[N];

bool check(int k)
{
	if(k>=X*n)
		return 1;

	int kawalek = k%X;
	int cale = k/X;

	for(int i = 0; i < n; ++i)
	{
		int teraz = start;

		if(i>=cale)
		{
			if(cale>0)
				teraz += pref[cale-1];
		}
		else
			teraz += pref[cale] - vec[i].st;

		int ind = vec[i].nd;

		if(kawalek<=b[ind])
			teraz += kawalek*l[ind];
		else
		{
			teraz += b[ind]*l[ind];
			teraz += (kawalek-b[ind])*u[ind];
		}

		if(teraz>=0)
			return 1;
	}

	return 0;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> X;

	for(int i = 1; i <= n; ++i)
	{
		cin >> b[i] >> l[i] >> u[i];
		vec.eb(X*u[i]-b[i]*(u[i]-l[i]), i);
		start -= b[i]*l[i];
	}

	sort(ALL(vec));
	reverse(ALL(vec));

	for(int i = 0; i < n; ++i)
	{
		pref[i] += vec[i].st;
		pref[i+1] += pref[i];
	}

	int l = 0, r = 1e18;

	while(l<r)
	{
		int m = (l+r)/2;

		if(check(m))
			r = m;
		else
			l = m+1;
	}

	cout << l << endl;
}

Measured memory_bytes: 5104
use std::io::{Read, Write};

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let q: usize = it.next().unwrap().parse().unwrap();
    let mut cnt = vec![0; n + 1];
    for _ in 0..q {
        let a: usize = it.next().unwrap().parse().unwrap();
        cnt[a] += 1;
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for c in cnt[1..].iter() {
        let ans = if q - *c < k {
            "Yes"
        } else {
            "No"
        };
        writeln!(out, "{}", ans).unwrap();
    }
}

fn main() {
    run();
}

Measured memory_bytes: 6780
#include<stdio.h>
#include<string.h>

char s[100010],t[100010];
int ans[30];
int main(){
	scanf("%s %s",s,t);
	int sn=strlen(s);
	int tn=strlen(t);
	if(tn==1){
		int cnt=0;
		for(int i=0;i<sn;i++)if(s[i]==t[0])cnt++;
		int ans=0;
		while(cnt>=(1<<ans)){
			cnt-=1<<ans;
			ans++;
		}
		printf("%d\n",ans);
		return 0;
	}
	int pos=0;
	for(int i=0;i<sn;i++){
		if(s[i]==t[ans[pos]]){
			ans[pos]++;
			if(pos==0&&ans[pos]==tn){
				while(ans[pos]==tn)ans[pos++]=0;
			}else pos=0;
		}
	}
	for(int i=0;i<30;i++)if(ans[i])pos=i;
	printf("%d\n",pos);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);
 
int N, M;
int adj[15][15], stor[1<<15][15], dp[1<<15][15];
vector<pii> nex[1<<15];
 
void gen(int i, int cur, int todo, int cost) {
    if (todo == N) {
        nex[i].pb({cur,cost});
        return;
    }    
    if ((i & (1<<todo)) == 0) gen(i,cur+(1<<todo),todo+1,cost+stor[i][todo]);
    gen(i,cur,todo+1,cost);
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    F0R(i,M) {
        int a,b,c; cin >> a >> b >> c;
        a--, b--;
        adj[a][b] = adj[b][a] = c;
    }
    
    F0R(i,1<<N) {
        F0R(j,N) {
            int tot = 0;
            F0R(k,N) if (i & (1<<k)) tot += adj[j][k];
            stor[i][j] = tot;
        }
        gen(i,0,0,0);
    }
    
    F0R(i,1<<N) F0R(j,N) dp[i][j] = MOD;
    dp[1][0] = 0;
    
    F0R(i,1<<N) if (i&1) F0R(j,N) if (i&(1<<j)) {
        F0R(k,N) if ((i&(1<<k)) == 0) if (adj[j][k]) dp[i^(1<<k)][k] = min(dp[i^(1<<k)][k],dp[i][j]+stor[i^(1<<j)][k]);
        for(pii a: nex[i]) dp[i^a.f][j] = min(dp[i^a.f][j],dp[i][j]+a.s-stor[a.f][j]);
    }
    
    cout << dp[(1<<N)-1][N-1];
}


Measured memory_bytes: 117500
#include<iostream>

using namespace std;

typedef long long ll;

const ll mod = (ll) 1e9 + 7;

ll dp[1010][1010];
char a[1010][1010];

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < h; ++i) {
        if (a[i][0] == '#') break;
        dp[i][0] = 1;
    }

    for (int j = 0; j < w; ++j) {
        if (a[0][j] == '#') break;
        dp[0][j] = 1;
    }

    for (int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (a[i][j] == '#') continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    }

    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 9088
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        long[,] cost = new long[N,N];
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0])-1;
            int B = int.Parse(str[1])-1;
            int C = int.Parse(str[2]);
            cost[A,B] = C;
            cost[B,A] = C;
        }
        long[] SC = new long[1 << N];
        for(int i=1;i<1 << N;i++){
            long count = 0;
            for(int j=0;j<N;j++){
                if(((1 << j) & i) != 0){
                    count += SC[i-(1 << j)];
                    for(int k=j+1;k<N;k++){
                        if(((1 << k) & i) != 0){
                            count += cost[j,k];
                        }
                    }
                    break;
                }
            }
            SC[i] = count;
        }
        long[,] DP = new long[1 << N,N];
        for(int i=1;i<N;i++){
            DP[0,i] = 10000000000;
        }
        for(int i=1;i<1 << N;i++){
            for(int j=0;j<N;j++){
                DP[i,j] = 10000000000;
                if(((1 << j) & i) != 0 || (i % 2 == 0 && j != 0)){
                    continue;
                }
                for(int k=0;k<N;k++){
                    if(((1 << k) & i) != 0 && cost[k,j] != 0){
                        DP[i,j] = Math.Min(DP[i-(1 << k),k]-SC[i-(1 << k)]+SC[i-(1 << k)+(1 << j)],DP[i,j]);
                    }
                }
                for(int k=i;k != 0;k = (k-1) & i){
                    DP[i,j] = Math.Min(DP[i-k,j]+SC[i]-SC[k]-SC[i-k],DP[i,j]);
                }
            }
        }
        sb.Append(DP[(1 << (N-1))-1,N-1]+"\n");
    }
}

Measured memory_bytes: 15072
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
enum D {
    L,
    R,
}

fn f(l: &Vec<char>, r: &Vec<char>) -> Option<(D, Vec<char>)> {
    if !r.iter().rev().zip(l).all(|(c1, c2)| c1 == c2) {
        return None;
    }
    if l.len() == r.len() {
        return Some((D::L, vec![]));
    }
    if l.len() > r.len() {
        Some((D::L, Vec::from(&l[r.len()..])))
    } else {
        Some((D::R, Vec::from(&r[..r.len() - l.len()])))
    }
}

fn g(v: &Vec<char>) -> bool {
    v.iter().rev().eq(v)
}

fn main() {
    input! {
        n: usize,
        mut sc: [(Chars, i64); n],
    }

    use std::cmp::{max, Reverse};
    let mut res = None;
    let mut memo = std::collections::BTreeMap::new();
    let mut q = std::collections::BinaryHeap::new();
    for (s, c) in &sc {
        q.push((Reverse(*c), (D::L, s.clone())));
    }
    sc.push((vec![], 0));
    while let Some((Reverse(c), s)) = q.pop() {
        if *memo.entry(s.clone()).or_insert(std::i64::MAX) < c {
            continue;
        }
        for j in 0..n + 1 {
            let x = if s.0 == D::L {
                f(&s.1, &sc[j].0)
            } else {
                f(&sc[j].0, &s.1)
            };
            if let Some(s) = x {
                if g(&s.1) {
                    res = max(res, Some(Reverse(c + sc[j].1)));
                    continue;
                }
                let r = memo.entry(s.clone()).or_insert(std::i64::MAX);
                let c = c + sc[j].1;
                if *r <= c {
                    continue;
                }
                *r = std::cmp::min(*r, c);
                q.push((Reverse(c), s));
            }
        }
    }

    println!("{}", res.unwrap_or(Reverse(-1)).0);
}


Measured memory_bytes: 2248
// <head>
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
// </head>

// <library>
    const int MOD = 998244353;
    struct mint {
      ll x; // typedef long long ll;
      mint(ll x=0):x((x%MOD+MOD)%MOD){}
      mint operator-() const { return mint(-x);}
      mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
      }
      mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
      }
      mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
      }
      mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
      }
      mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
      }
      mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
      }
      mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
      }
      // for prime MOD
      mint inv() const {
        return pow(MOD-2);
      }
      mint& operator/=(const mint a) {
        return (*this) *= a.inv();
      }
      mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
      }
    };
    ostream& operator<< (ostream& os, const mint& value) {
      os << value.x;
      return os;
    }
    
// </library>
const int MX = 3005;
mint dp[MX][MX][3];

int main(){
    int n,s; cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }

    dp[0][0][0] = 1;
    for (int i = 1; i < n+1; i++){
        for (int j = 0; j < MX-1; j++){
            for (int k = 0; k < 3; k++){
                int pi = i-1,pj=j-a[pi];
                int pk = k-1;
                dp[i][j][k] = dp[pi][j][k];
                if(pj >= 0 && k==1) dp[i][j][k] += dp[pi][pj][k]  + dp[pi][pj][pk];
                if(pk>=0) dp[i][j][k] += dp[pi][j][pk];
            }
        }
    } 
    cout << dp[n][s][1] + dp[n][s][2] << '\n';
    
}

Measured memory_bytes: 211968
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, M;
    cin >> N >> M;

    vec<vec<pair<int, int>>> G(N);
    vec<vec<int>> W(N, vec<int>(N, 1e9 + 7));
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
        W[a][b] = c;
        W[b][a] = c;
    }
    rep(i, N) W[i][i] = 0;

    function<void(int)> warshall_floyd = [&](int n) {
        for (int k = 0; k < n; k++) {            // 経由する頂点
            for (int i = 0; i < n; i++) {        // 始点
                for (int j = 0; j < n; j++) {    // 終点
                    W[i][j] = min(W[i][j], W[i][k] + W[k][j]);
                }
            }
        }
    };
    warshall_floyd(N);

    set<pair<int,int>> s;

    function<void(int, int, int, int, int, vec<int>)> dfs =
        [&](int now, int par, int end, int d, int maxd, vec<int> v) {
            if(now==end && d ==maxd){
                for(int i=1;i<v.size();++i){
                    int a = v[i-1];
                    int b = v[i];
                    if(a>b) swap(a,b);
                    s.insert({a,b});
                }
                return;
            }
            for (auto e : G[now]) {
                int next = e.first;
                int dist = e.second;
                if (next == par) continue;
                if (d + dist > maxd) continue;
                v.push_back(next);
                dfs(next, now, end, d + dist, maxd, v);
                v.pop_back();
            }
        };

    rep(i, N) rep(j, i) {
        dfs(j, -1, i, 0, W[j][i], vec<int>(1,j));
    }
    cout << M-s.size() << '\n';
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int h, n;
    cin >> h >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    rep(i, n) {
        h -= a[i];
        if (h <= 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}


Measured memory_bytes: 640