akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<V<int>> dp(n, V<int>(n)), cst(n, V<int>(n, 1));
    int t = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i][j] = min({i, j, n - 1 - i, n - 1 - j}) + 1;
        }
    }
    ll res = 0;
    queue<P> q;
    for (int i = 0; i < n * n; i++) {
        int p;
        cin >> p;
        --p;
        int sy = p / n, sx = p % n;
        --dp[sy][sx];
        --cst[sy][sx];
        q.emplace(sy, sx);
        while (!q.empty()) {
            int y = q.front().fi, x = q.front().se;
            q.pop();
            for (int j = 0; j < 4; j++) {
                int ny = y + dy[j], nx = x + dx[j];
                if (ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
                if (dp[ny][nx] > dp[y][x] + cst[ny][nx]) {
                    dp[ny][nx] = dp[y][x] + cst[ny][nx];
                    q.emplace(ny, nx);
                }
            }
        }
        // cout << p + 1 << " " << dp[sy][sx] << newl;
        res += ll(dp[sy][sx]);
    }
    cout << res << newl;
}

Measured memory_bytes: 5540
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    ll ans=s[k-1]-s[0]+min(abs(s[0]),abs(s[k-1]));
    for(int i=0;i<n-k+1;i++){
        ll p=s[i+k-1]-s[i]+min(abs(s[i+k-1]),abs(s[i]));
        ans=min(ans,p);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){

  int from = 0;
  int to = 0;
  int i = 0;
  int count = 0;
  int flag = 0;

  while(1){
    count = 0;
    scanf("%d", &from);
    scanf("%d", &to);

    if((from == 0) && (to == 0)){
      return 0;
    }
    if(flag == 0){
      flag = 1;
    }else{
      printf("\n");
    }
    for(i = from; i <= to; i++){
      if(i % 400 == 0){
        printf("%d\n", i);
        count++;
      }else if((i % 4 == 0) && (i % 100 != 0)){
        printf("%d\n", i);
        count++;
      }
    }
    if(count == 0){
      printf("NA\n");
    }
  }

  return 0;
}

Measured memory_bytes: 616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var words = new List<string>();
            var word = Console.ReadLine();
            words.Add(word);

            for (int i = 0; i < N - 1; i++)
            {
                var W = Console.ReadLine();
                if (W[0] != word[word.Length - 1] || words.Contains(W))
                {
                    Console.WriteLine("No");
                    return;
                }
                word = W;
                words.Add(W);
            }

            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N, K;
  cin >> N >> K;
  ll ans;
  cout << (N-1 + K - 2) / (K-1) << endl;
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll dp[100099];
ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

ll calc(ll n) {
	if(dp[n] != -1) {
		return dp[n];
	}
	if(n == 100 || n==101 || n==102 || n==103 || n==104 || n==105) {
		return 1;
	}
	if(n < 100) {
		return 0;
	}
	dp[n] = calc(n-100) | calc(n-101) | calc(n-102) | calc(n-103) | calc(n-104) | calc(n-105);
	return dp[n];
}

void solve()
{
    ll x;
    cin >> x;
    for(ll i=1;i<=x;i++) {
    	dp[i] = -1;
    }
    cout << calc(x) << "\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1024
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
    }
    rep(i, n){
        cout << cnt[i] << endl;
    }
    return 0;
}

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

int gcd(int a, int b){
    if(b > a)swap(a, b);
    if(b == 0){
        return a;
    }
    return gcd(a%b, b);
}

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

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

    sort(A.begin(), A.end());
   
    int ans = A[0];
    for(int i = 1; i < A.size(); i++){
       ans = gcd(ans, A[i]);
    }
     
    cout << ans << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    int k;
    cin>>k;
    vector<priority_queue<ll,vector<ll>,greater<ll>>> vq;
    priority_queue<ll,vector<ll>,greater<ll>> q1;
    rep(i,9){
        q1.push(i+1);
        //cout<<q1.top()<<endl;
    }
    vq.push_back(q1);
    for (int i=2;i<11;i++){//桁数
        priority_queue<ll,vector<ll>,greater<ll>> q2;
        priority_queue<ll,vector<ll>,greater<ll>> q11=vq[i-2];
        ll num=q11.size();
        rep(j,num){
            ll num1=q11.top();
            //cout<<num1<<endl;
            q11.pop();
            int num2=num1%10;
            if (num2==0){
                q2.push(num1*10);
                q2.push(num1*10+1);
            }
            else if (num2==9){
                q2.push(num1*10+9);
                q2.push(num1*10+8);
            }
            else{
                q2.push(num1*10+num2+1);
                q2.push(num1*10+num2);
                q2.push(num1*10+num2-1);
            }
        }
        vq.push_back(q2);
    }
    int now=0;
    int index;
    while (1){
        if (k<vq[now].size()){
            index=now;
            break;
        }
        else{
            k-=vq[now].size();
            now+=1;
        }
    }
    ll ans;
    while(k>0){
        k-=1;
        ans=vq[index].top();
        vq[index].pop();
    }
    cout<<ans<<endl;



    return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> H(n);
    rep(i, n) cin >> H[i];

    int ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        bool ok = true;
        for (int j = i - 1; j >= 0; --j) {
            if (H[i] < H[j]) {
                ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#x,y,z = list(map(int,input().split()))
# k = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for kk in range(1,k+1):
            ans += gcd(i,j,kk)


print(ans)


Measured memory_bytes: 69824
using System;

namespace ITP1_9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            input1 = input1.ToLower();
            int num = 0;
            bool flg = true; 

            while (flg == true)
            {
                string[] input2 = Console.ReadLine().Split(' ');
                foreach(string str in input2)
                {
                    if (str == "END_OF_TEXT")
                    {
                        flg = false;
                        break;
                    }

                    string value = str.ToLower();
                    if (input1 == value) num++;
                }
            }

            Console.WriteLine(num);
        }
    }
}

Measured memory_bytes: 9108
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back
#define mp make_pair

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

#define M 1'000'000'007

vector<string> g;

int memo[1005][1005];
ll dp(int at1, int at2) {
  if (at1 == -1 || at2 == -1) return 0;
  if (g[at1][at2] == '#') return 0;
  if (at1 == 0 && at2 == 0) return 1;

  if (memo[at1][at2] != -1) return memo[at1][at2];

  ll ret = dp(at1 - 1, at2) + dp(at1, at2 - 1);
  ret %= M;
  return memo[at1][at2] = ret;
}

int main() {
  // code
  memset(memo, -1, sizeof(memo));

  int h, w;
  cin >> h >> w;

  rep(i, 0, h) {
    string s;
    cin >> s;
    g.pb(s);
  }

  cout << dp(h - 1, w - 1) << endl;

  // codend
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=100100100;
const ll  INF=1000000000000000100;//10の18乗
const int mod=(int)1e9+7;

int n,q;
vector<vector<int>>g;
vector<ll>c;
void dfs(int pa,int i){
    for(auto ch:g.at(i)){
        if(ch==pa)continue;
        c.at(ch)+=c.at(i);
        dfs(i,ch);
    }
}
int main(){
    cin>>n>>q;
    g.resize(n);
    c.resize(n);
    rep(i,0,n-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }
    rep(i,0,q){
        int p,x;
        cin>>p>>x;
        p--;
        c.at(p)+=x;
    }
    dfs(-100,0);
    rep(i,0,n){
        cout<<c.at(i)<<endl;
    }
return 0;
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int a1, a2, a3, b1, b2, b3;
  vector<int> c(9);
  rep_i(i, 9){
    cin >> c[i];
  }
  

  for (int i = 0; i <= c[0]; i++){
    a1 = i;
    b1 = c[0] - a1;
    b2 = c[1] - a1;
    b3 = c[2] - a1;

    a2 = c[3] - b1;
    a3 = c[6] - b1;
    if(a1 + b1 == c[0] && a1 + b2 == c[1] && a1 + b3 == c[2] && a2 + b1 == c[3] && a2 + b2 == c[4] && a2 + b3 == c[5] && a3 + b1 == c[6] && a3 + b2 == c[7] && a3 + b3 == c[8]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  

  // a2 = c[3];
  // a3 = c[6];
  // b1 = 0;
  // b2 = 0;
  // b3 = 0;
  // for (int i = 0; i <= a1; i++){
  //   a1 -= i;
  //   b1 = i;
  //   for (int v = 0; v <= a2; v++){
  //     a2 -= v;
  //     b2 = v;
  //     for (int w = 0; w <= a3; w++){
  //       a3 -= w;
  //       b3 = w;
  //       if(a1 + b1 == c[0] && a1 + b2 == c[1] && a1 + b3 == c[2] && a2 + b1 == c[3] && a2 + b2 == c[4] && a2 + b3 == c[5] && a3 + b1 == c[6] && a3 + b2 == c[7] && a3 + b3 == c[8]){
  //         cout << "Yes" << endl;
  //         return 0;
  //       }
  //     }
  //   }
  // }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF (1 << 20)
#define MAX_V 200

int path[MAX_V];
int cost[MAX_V][MAX_V];
bool used[MAX_V];
int d[MAX_V];

// ?????????O(V^2)

void shortest_path(int s, int V){ // V???????????°
	for(int i = 0; i < V; i++){
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	path[s] = -1;
	
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || d[u] < d[add_v])){
				add_v = u;
			}
		} // ??´??°????????????????±????
		//cout << add_v << " ";
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		
		for(int u = 0; u < V; u++){
			if(d[add_v] + cost[add_v][u] < d[u]){
				d[u] = d[add_v] + cost[add_v][u];
				path[u] = add_v;
			}
		} // ???????????????????????????????°???????????????´??°
	}
}

void path_track2(int num){
	if(num == -1){
		return;
	}
	path_track2(path[num]);
	cout << num + 1 << " ";
}

void path_track(int num){
	if(num == -1){
		cout << endl;
		return;
	}
	path_track2(path[num]);
	cout << num + 1 << endl;
}

int main(){
	
	int V, m;
	
	while(true){
		
		cin >> V;
		
		if(V == 0){
			break;
		}
		
		double pos_x[200], pos_y[200];
		
		for(int i = 0; i < V; i++){
			int b;
			double x, y;
			cin >> b >> x >> y;
			pos_x[b - 1] = x;
			pos_y[b - 1] = y;
			path[b - 1] = -1;
		}
		
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				if(i == j){
					cost[i][j] = INF;
				}else if((pos_x[i] - pos_x[j]) * (pos_x[i] - pos_x[j]) + (pos_y[i] - pos_y[j]) * (pos_y[i] - pos_y[j]) <= 2500){
					cost[i][j] = sqrt((pos_x[i] - pos_x[j]) * (pos_x[i] - pos_x[j]) + (pos_y[i] - pos_y[j]) * (pos_y[i] - pos_y[j]));
				}else{
					cost[i][j] = INF;
				}
			}
		}
		
		cin >> m;
		
		for(int loop = 0; loop < m; loop++){
			int s, g;
			cin >> s >> g;
			s--;
			g--;
			
			shortest_path(s, V);
			
			if(d[g] >= INF){
				cout << "NA" << endl;
			}else{
				path_track(g);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3132
fun main(args: Array<String>) {
    val mod = 1000000007L
    val N = readInputLine().toInt()
    
    val dp = LongArray(N)
    dp[0] = 1L
    val lastIndex = IntArray(200001) { -1 }
    
    lastIndex[readInputLine().toInt()] = 0
    
    for (i in 1 until N) {
        val c = readInputLine().toInt()
        if (lastIndex[c] != -1 && i - lastIndex[c] != 1) {
            dp[i] = dp[i - 1] + dp[lastIndex[c]]
            dp[i] %= mod
        } else {
            dp[i] = dp[i - 1]
        }
        lastIndex[c] = i
    }

    println(dp[N - 1])
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 45044
#include<bits/stdc++.h>
#define rp(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;
    string s;
    cin >> n >> s;
    int ctr=1;
    rp(i,n-1){
        if(s.at(i)!=s.at(i+1)) ctr++;
    }
    cout << ctr << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

main(){
	int x[100000];
	int i,c;
	i = 0;
	c = 1;
	while(1){
		scanf("%d",&x[i]);
	    if(x[i]==0)break;
	    i++;
	    c++
	    ;
	}
	for(i=1;i<c;i++){
		printf("Case %d: %d\n",i,x[i-1]);
	}
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

LL MM = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  VEC<int> A(M);
  set<int> S;
  REP(i, 0, M) {
    cin >> A[i];
    S.insert(A[i]);
  }
  // DUMP(S);
  sort(ALL(A));
  VEC<LL> p(N + 1, 0);
  p[0] = 1;
  if (S.count(1)==0) p[1] = 1;
  REP(i, 2, N + 1) {
    LL next = 0;
    if (S.count(i - 1) == 0) {
      next += p[i - 1];
    }
    if (S.count(i - 2) == 0) {
      next = (p[i - 2] + next) % MM;
    }

    p[i] = next % MM;
  }
  // DUMP(p);
  cout << p[N] << endl;

  return 0;
}


Measured memory_bytes: 6144
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,r,s_n;
    cin>>n;
    s_n=n;
    int sum=0;
    while(s_n){
        r=s_n%10;
        sum+=r;
        s_n/=10;
    }
    if(n%sum==0){
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;

}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int a;
    scanf("%d", &a);
    
    if(a<=999)
    {
        printf("ABC");
    }
    
    else if(a>=1000 and a<=1998)
    {
        printf("ABD");
    }
    
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair


using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> a,b,c;

    rep(i,n){
        int tmp;
        cin >> tmp;
        a.pback(tmp);
    }
    
    rep(i,n){
        int tmp;
        cin >> tmp;
        b.pback(tmp);
    }

    rep(i,n){
        int tmp;
        cin >> tmp;
        c.pback(tmp);
    }

    sorta(a);
    sorta(b);
    sorta(c);

    int ai = 0;
    vector<ll> ab;

    //ab[i]はb[i]にたいしてそれより小さいaの数をあらわす

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

        while(ai < n && a[ai] < b[i]){
            ai++;
        }

        ab.pback(ai);
    }

    int bi = 0;
    vector<ll> bc;

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

        while(bi < n && b[bi] < c[i]){
            bi++;
        }
        
        bc.pback(bi);
    }

    //abの累積和を用意する
    vector<ll> ais;

    ais.pback(0);

    rep(i,n){
        ais.pback(ais[i] + ab[i]);
    }

    ll ans = 0;

    rep(i,n){

        ans = ans + ais[bc[i]];
    }

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

Measured memory_bytes: 4596
#![allow(non_snake_case, unused)]
use std::io::*;
use std::str::FromStr;
use std::collections::*;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let s: String = sc.next();
    let t: String  = sc.next();

    let s: Vec<_> = s.as_str().chars().collect();
    let t: Vec<_> = t.as_str().chars().collect();
    let n = s.len();
    let m = t.len();

    let mut ans = m;
    for i in 0..=(n - m) {
	let sl = &s[i..];
	let mut cnt = 0;
	for j in 0..m {
	    if sl[j] != t[j] {
		cnt += 1;
	    }
	}

	ans = ans.min(cnt);
    }
    println!("{}", ans);
}


// Scanner
struct Scanner<R: std::io::Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
	Scanner { reader: reader }
    }

    fn read<T: FromStr> (&mut self) -> Option<T> {
	let token = self
	    .reader
	    .by_ref()
	    .bytes()
	    .map(|c| c.unwrap() as char)
	    .skip_while(|c| c.is_whitespace())
	    .take_while(|c| !c.is_whitespace())
	    .collect::<String>();
	if token.is_empty() {
	    None
	} else {
	    token.parse::<T>().ok()
	}
    }

    fn next<T: FromStr>(&mut self) -> T {
	if let Some(s) = self.read() {
	    s
	} else {
	    writeln!(stderr(), "Terminated with EOF").unwrap();
	    std::process::exit(0);
	}
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
	(0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
	self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 2192
import sys
input = sys.stdin.readline
INF = 10**9
MOD = 10**9 + 7

def main():
    a,b = map(int,input().split())
    
    if a == 1 and b == 1:
        print(1,2)
        print('.#')
        exit()

    if a != 1:
        h1 = 2 * ((a - 2)//50 + 2) - 1
        lim1 = 1
        grid1 = [['#']*100 for _ in range(h1)]
    else:
        h1 = 0
        lim1 = 0

    if b != 1:
        h2 = 2 * ((b - 2)//50 + 1)
        lim2 = 1
        grid2 = [['.']*100 for _ in range(h2)]
    else:
        h2 = 0
        lim2 = 0
    
    i = 1
    j = 1
    while a > lim2:
        grid1[i][j] = '.'
        a -= 1
        j += 2
        if j == 101:
            i += 2
            j = 1
    
    i = 1
    j = 1
    while b > lim1:
        grid2[i][j] = '#'
        b -= 1
        j += 2
        if j == 101:
            i += 2
            j = 1

    print(h1 + h2, 100)

    for i in range(h1):
        print(''.join(grid1[i]))

    for i in range(h2):
        print(''.join(grid2[i]))

if __name__=='__main__':
    main()

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

#define Max 1000000

int prime [10000000];

int main()
{
	int n, out;
	for (int i = 2; i * i < Max; i++){
		if (prime[i] == 0){
			for (int j = i; j < Max; j += i){
				if (!(j == i)) prime[j] = 1;
			}
		}
	}
	while (cin >> n){
		out = 0;
		for (int i = 0; i <= n; i++){
			if (prime[i] == 0) out++;
		}
		cout << out - 2 << endl;
	}
	return(0);
}

Measured memory_bytes: 6992
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

int main(){
    ll n,k; cin >> n >> k;
    vector<int> da(n);
    rip(i,n,0) {cin >> da[i];--da[i];}
    vector<int> co(n,-1);
    co[0] = 0;
    int next = da[0], now = 0;
    while(co[next] == -1){
        co[next] = co[now]+1;
        now = next;
        next = da[now];
    }
    int d = co[next], c = co[now]-co[next]+1;
    int ans = 0;
    if(k <= d){
        ans = k;
    }
    else{
        ans = (k-d)%c + d;
    }
    // cout << c MM d MM ans << endl;
    rip(i,n,0){
        if(co[i] == ans){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4844
import sys
input = sys.stdin.readline

N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
score = -10 ** 18

for i in range(1 << 10):
    t = []
    
    for j in range(10):
        if (i >> j) & 1:
            t.append(j)
            
    if t == []:
        continue
        
    s = [0] * N
    for j in range(N):
        p = F[j]
        c = 0
        for tt in t:
            if p[tt] == 1:
                c += 1
        s[j] = P[j][c]
    
    score = max(score, sum(s))
    
print(score)

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

int main()
{
   int n, x;
   int ai, a, bi, b;
   cin >> n;
   int p[60];
   int mispl =0;
   for (int i = 1; i <= n; i++)
   {
       cin >> x;
       if (x!=i) 
       {
            mispl++;
            if (mispl == 1)
            {
                ai = i;
                a = x;
            }
            else if (mispl == 2)
            {
                bi = i;
                b = x;
            }
        }
        if (mispl>2)
        {
           cout << "NO\n";
           return 0;
        } 
   }
    
    if (mispl == 0)
    {
        cout << "YES\n";
        return 0;
    }
    if (mispl == 1)
    {
        cout << "NO\n";
        return 0;
    }
    if (ai == b && bi == a)
        cout << "YES\n";
    else
        cout << "NO\n";

}
    

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
		int hight[10];
		int i = 0;
		int tmp;
		int j = 0;

		for(i=0;i<10;i++){
				scanf("%d",&hight[i]);
		}

		for(i=0;i<10;i++){
			for(j=0;j<9;j++){
				if(hight[j] < hight[j+1]){
						tmp = hight[j];
						hight[j] = hight[j+1];
						hight[j+1] = tmp;
				}
			}
		}
		for(i=0;i<3;i++){
				printf("%d\n",hight[i]);
		}
		return 0;
}
			

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;
int main()
{
	string a, b;
	cin >> a >> b;
	if (a > b) {
		cout << ">" << endl;
	}
	if (a < b){
		cout << "<" << endl;
	}
	if (a == b) {
		cout << "=" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if (a<b){
  cout<<"a"<<" < "<<"b"<<endl;
  } else if (a>b) {
  cout<<"a"<<" > "<<"b"<<endl;
  } else if (a==b){
  cout<<"a"<<" == "<<"b"<<endl;	 
  } return 0;
  
  }

Measured memory_bytes: 3092
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return str(sys.stdin.readline())

def main():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ng=-1,ok=n;
    while(ok-ng>1){
        ll mid=(ok+ng)/2;
        int cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]==cnt+1){
                cnt++;
            }
        }
        if(n-mid<=cnt)ok=mid;
        else ng=mid;
    }
    if(ok==n){
        cout<<-1<<endl;
    }
    else{
        cout<<ok<<endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,k;cin >> n >> k;
    vl v(n);rep(i,n)cin >> v[i];
    rev(all(v));
    vl dp(n+1,0);
    vl pls(200010,-1);
    rep(i,n){
        if(pls[v[i]]==-1){
            dp[i+1]=v[i];
        }
        else{
            dp[i+1]=dp[pls[v[i]]];
        }
        pls[v[i]]=i;
    }
    vl to(200010,-1);
    per(i,n){
        if(to[v[i]]==-1)to[v[i]]=dp[i];
    }
    to[0]=dp[n];
    ll now=0,t=0,loop;vl seen(200010,-1);
    seen[0]=0;
    k--;

    rev(all(v));
    vector<set<ll>> st(200010);
    rep(i,n)st[v[i]].ins(i);


    while(true){
        t++;
        if(t==k+1){
            ll p=-1;
            while(p<n){
                if(st[now].upper_bound(p)==st[now].end()){
                    if(now)cout << v[p] <<" ";
                    p++;now=v[p];
                }
                else{
                    p=*st[now].upper_bound(p);
                    p++;now=v[p];
                }
            }
            cout << endl;
            return 0;
        }
        ll next=to[now];
        now=next;
        if(seen[next]!=-1){
            loop=t-seen[next];
            break;
        }
        seen[now]=t;
    }
    k=(k-seen[now])%loop;
   //cout << k <<" " << seen[now] << " " << loop <<endl;
    rep(i,200010){
        if(seen[i]==k+seen[now]){
            ll p=-1;
            while(p<n){
                if(st[i].upper_bound(p)==st[i].end()){
                    if(i)cout << v[p] <<" ";
                    p++;i=v[p];
                }
                else{
                    p=*st[i].upper_bound(p);
                    p++;i=v[p];
                }
            }
            cout << endl;
            return 0;
        }
    }
}   

Measured memory_bytes: 29924
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	static	ArrayList<Integer> G = new ArrayList<Integer>();
	static int cnt = 0;
	
	public static void main(String arg[]) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String wdn = br.readLine();
		int N = Integer.parseInt(wdn);
		int A[] = new int[N+1];
		for (int i=0; i<N; i++){
			wdn = br.readLine();
			A[i] = Integer.parseInt(wdn);
		}
		
		shellSort(A, N);
		
		
		StringBuilder sb = new StringBuilder();
		
		sb.append(G.size() + "\n");
		for (int i = G.size()-1; i>0; i--) sb.append(G.get(i) + " ");
		sb.append(G.get(0) + "\n");
		sb.append(cnt + "\n");
		
		for (int i=0; i<N-1; i++){
			sb.append(A[i] + "\n");
		}
		sb.append(A[N-1]);
		System.out.println(sb);
	}
		
	
	static void shellSort(int[] A, int n){
		for(int h = 1;;){
			if(h>n) break;
			G.add(h);
			h = 3*h + 1;
		}
		for (int i=G.size()-1; i>=0; i--){
			insertionSort(A, n, G.get(i));
		}
	}
	
	static void insertionSort(int[] A, int n, int g){
		int v;
		int j;
		for (int i=g; i<n; i++){
			v = A[i];
			j = i - g;
			while (j >= 0 && A[j] > v){
			    A[j+g] = A[j];
			    j = j - g;
				cnt++;
			}
			A[j+g] = v;
		}
	}
}


Measured memory_bytes: 147828
#include <iostream>
#include <cstdio>

using namespace std;

#define ll long long

ll n;
ll s;

int main()
{
	cin >> n;
	int i = 1;
	while (true)
	{
		if ((360 * i) % n == 0)
		{
			cout << (360 * i) / n;
			break;
		}
		++ i;
	}
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, K;
	cin >> N >> K;
	int x[N];
	for(int i = 0; i < N; i++) cin >> x[i];
	
	int rslt = 0;

	for(int i = 0; i < N; i++) {
		rslt += 2 * min(x[i], K - x[i]);	
	}
	cout << rslt << endl;
}


Measured memory_bytes: 256
// B - Frog2

#include <bits/stdc++.h>

using namespace std;

// DP時の道具
template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		// aよりbの方が小さかったら、aの値をbの値に置き換える
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		// aよりbの方が大きかったら、aの値をbの値に置き換える
		a = b;
		return true;
	}
	return false;
}


int main() {
	int N, K, t;
	cin >> N >> K;
	vector<int> h;
	for (int i = 0; i < N; i++) {
		cin >> t;
		h.push_back(t);
	}

	const int INF = (1 << 30);
	
	// 初期化
	vector<int> dp = {0};
	for (int i = 1; i < N; i++) {
		dp.push_back(INF);
	}

	// 更新
	for (int i = 0; i < N-1; i++) {
		for (int j = 1; j <= K; j++) {
			if (i+j < N) {
				chmin(dp.at(i+j), dp.at(i) + abs(h.at(i) - h.at(i+j)));
			}
		}
	}

	// 出力
	cout << dp.at(N-1) << endl;
}


Measured memory_bytes: 1400
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

char s[maxn];
const ll mod=1000000007;
ll dp[maxn][2];

int main()
{
	scanf("%s",s+1); ll len=strlen(s+1),p=1,cnt=0,ans=0,a1=0;
	for(int i=1;i<=len;i++) if(s[i]=='1') cnt++;
	dp[len+1][0]=1;
	for(int i=len;i>=1;i--)
	{
		if(s[i]=='1')
		{
			dp[i][0]=(dp[i+1][1]+dp[i+1][0]*3)%mod;
			dp[i][1]=(dp[i+1][1]*2);
		}
		else
		{
			dp[i][0]=dp[i+1][0];
			dp[i][1]=(dp[i+1][1]*3+dp[i+1][0]*2)%mod;
		}
	}
	//for(int i=1;i<=len;i++) cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	cout<<dp[1][0]<<endl;
	return 0;
}

Measured memory_bytes: 3840
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  ios::sync_with_stdio(false);
  string s;
  priority_queue<int> q;
  while (cin >> s, s != "end") {
    if (s == "insert") {
      int k;
      cin >> k;
      q.push(k);
    }
    if (s == "extract") {
      cout << q.top() << endl;
      q.pop();
    }
  }
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int K, N;
map<int, int> val;
vector< pair<int, int> > forSort;

int main()
{
    cin >> N >> K;
    REP(i, N) {
        int a;
        cin >> a;
        val[a]++;
    }
    for(auto& m : val) {
        forSort.push_back(make_pair(m.second, m.first));
    }
    sort(forSort.begin(), forSort.end(), greater< pair<int, int> >() );
    int ans = 0;
    while(forSort.size() > K) {
        pair<int, int> tmp = forSort[forSort.size()-1];
        ans += tmp.first;
        forSort.pop_back();
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 11768
n=int(input())
li=["a"]
alpha=["a","b","c","d","e","f","g","h","i","j"]
if n==1:
    print("a")
    exit()
else:
    for i in range(n-1):
        ans=[]
        for j in range(len(li)):
            for k in range(len(set(li[j]))+1):
                ans.append(li[j]+alpha[k])
        li=ans
for i in range(len(ans)):
    print(ans[i])



Measured memory_bytes: 12976
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

// LIS
// dp[i] := ながさ i にしたときの最小要素
// O(n log n)

vector<long long> LongestIncreasingSubsequence(vector<long long> &a) {
  
  size_t n = a.size();
  vector<long long> dp(n + 1, INF);
  for(size_t i = 0; i < n; i++) {
    *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }

  return dp;
}

int main() {
  int n; cin >> n;
  vector<lnt> a(n);

  for(int i = 0; i < n; i++) cin >> a[i];
  auto hoge = LongestIncreasingSubsequence(a);
  cout << lower_bound(hoge.begin(), hoge.end(), INF) - hoge.begin() << endl;
  return 0;
}



Measured memory_bytes: 4412
#include<bits/stdc++.h>
    using namespace std;
    int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin >> n;
      if(n>=30)cout<< "Yes"<< "\n";
      else cout << "No"<< "\n";
      return 0;
    }

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    int x=tx-sx,y=ty-sy;
    FOR(i,0,x)cout<<"R";
    FOR(i,0,y)cout<<"U";
    FOR(i,0,x)cout<<"L";
    FOR(i,0,y)cout<<"D";
    cout<<"D";
    FOR(i,0,x+1)cout<<"R";
    FOR(i,0,y+1)cout<<"U";
    cout<<"L";
    cout<<"U";
    FOR(i,0,x+1)cout<<"L";
    FOR(i,0,y+1)cout<<"D";
    cout<<"R"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, m; cin >> n >> m;
  vector<int> a(m), b(m);
  vector<vector<int>> G(n);
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }

  vector<int> color(n, -1);
  function< void(int,int,int) > dfs =
  [&](int u, int pre, int t){
    color[u] = t^1;
    for(int v : G[u]){
      if(v == pre) continue;
      if(color[v] == -1) dfs(v, u, t^1);
      else if(color[v] != t){
        cout << n*(n-1)/2 - m << endl;
        exit(0);
      }
    }
    return;
  };
  dfs(0, -1, 0);

  int left = 0, right = 0;
  for(int i = 0; i < n; i++){
    if(color[i] == 0) left++;
    else right++;
  }
  cout << left * right - m << endl;

  return 0;
}


Measured memory_bytes: 9472
N, M = map(int, input().split())

dp = [0 for _ in range(N + 1)]
can_use = [True for _ in range(N + 1)]

for _ in range(M):
    k = int(input())
    can_use[k] = False

dp[0] = 1
dp[1] = 1 if can_use[1] else 0
for i in range(2, N + 1):
    if not can_use[i]:
        continue
    dp[i] = dp[i - 1] + dp[i - 2]

print(dp[N] % (10 ** 9 + 7))


Measured memory_bytes: 460824
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

// -  0  1  00  10  100  11  110  
int const mod = 1e9 + 7;
int zero[10] = {1, 3, 4, 1, 5, 4, 7, 8, 7};
int one[10] = {2, 0, 6, 1, 2, 4, 6, 6, 7};
char s[300005];
int f[300005][10];

signed main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  cin >> (s + 1);
  int len = strlen(s + 1);
  f[0][0] = 1;
  for (RI i = 1; i <= len; ++i)
    for (RI j = 0; j <= 8; ++j) {
      if (s[i] != '0') (f[i][one[j]] += f[i - 1][j]) %= mod; 
      if (s[i] != '1') (f[i][zero[j]] += f[i - 1][j]) %= mod;
    }
  printf("%lld\n", (f[len][2] + f[len][7] + f[len][8] + f[len][6]) % mod);

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 24832