akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    #define back_sort(a) sort(all((a)),[](const int &p,const int &q){return p > q;})
    using intv = vector<int>;
    using douv = vector<double>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
    void YN (bool b){
        if(b){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    strcin(s);
    int n = s.size();
    int flag = 0;
    rap(n,i){
        if(0<= i && i <=1){
            if(s[0]!='A' || (65 <= s[1] && s[1] <= 90)){
                        // cout<<1;
                        cout<<"WA"<<endl;
                        return 0;
            }
        }else if(2 <= i && i <= n-2){
            if(s[i] == 'C'){
                flag ++;
            }else if(65 <= s[i] && s[i] <= 90){
                // cout<<2;
                cout<<"WA"<<endl;
                return 0;
            }
        }else{
            if(65 <= s[i] && s[i] <= 90){
                // cout<<3;
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(flag == 1){
        cout<<"AC"<<endl;
    }else{
        // cout<<4;
        cout<<"WA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, Ma, Mb; 
	cin >> N >> Ma >> Mb; 
	int A[50] = {}, B[50] = {}, C[50] = {}; 
	for(int k = 1; k <= N; k++){
		cin >> A[k] >> B[k] >> C[k]; 
		}
	int dp[410][410][45] = {}; 
	for(int i = 0; i < 410; i++){
		for(int j = 0; j < 410; j++){
			for(int k = 0; k < 45; k++){
				dp[i][j][k] = 114514;
			}
		}
	}
	dp[0][0][0] = 0; 
	for(int k = 1; k <= N; k++){
		for(int i = 0; i <= 10 * k; i++){
			for(int j = 0; j <= 10 * k; j++){
				if(i >= A[k] && j >= B[k]){
					dp[i][j][k] = min({dp[i-A[k]][j-B[k]][k-1] + C[k], dp[i][j][k-1], 114514}); 
                }
				else{
                  	dp[i][j][k] = dp[i][j][k-1];
                }
			}
		}
	}
	int t = min(400/Ma, 400/Mb); 
	int ans = 114514; 
	for(int l = 1; l <= t; l++){
		ans = min(ans, dp[l * Ma][l * Mb][N]);
	}
	if(ans < 114514){
		cout << ans << endl; 
	}
	if(ans == 114514){
		cout << -1 << endl; 
	}
}

Measured memory_bytes: 29824
#include<iostream>
using namespace std;
int main(){
  int x[10000];
  int num=0;
  int c=1;
  while(c){
    cin>>x[num];
    c=x[num];
    num++;
  }
  for(int a=0;a<num-1;a++){
    cout<<"Case "<<a+1<<": "<<x[a]<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int A[3][3];
  int N;
  int result[3][3];

  for (int j = 0; j < 3; j++) {
    for (int k = 0; k < 3; k++) {
      result[j][k] = 0; 
    }
  }
  
  cin >> A[0][0] >> A[0][1] >> A[0][2];
  cin >> A[1][0] >> A[1][1] >> A[1][2];
  cin >> A[2][0] >> A[2][1] >> A[2][2];
  cin >> N;
  int b[N];
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (b[i] == A[j][k]) {
          result[j][k] = 1;
        }
      }
    }
  }
  
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    if (result[i][0] && result[i][1] && result[i][2]) {
      ok = true;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (result[0][i] && result[1][i] && result[2][i]) {
      ok = true;
    }
  }
  if (result[0][0] && result[1][1] && result[2][2]) {
    ok = true;
  }
  if (result[2][0] && result[1][1] && result[0][2]) {
    ok = true;
  }
  
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

int readInt() {
	int n, c;
	while ((c = getchar()) < '0');
	n = c - '0';
	while ((c = getchar()) >= '0') {
		n = n * 10 + c - '0';
	}
	return n;
}

const int N = 5000;
const int M = 200;
int n, m;
int mono[M][N + 1];
int sp[M];
long long a[N];
long long b[N + 1][M];
long long val[N];
long long imos[N + 1];

int main() {
	n = readInt();
	m = readInt();
	for (int i = 1; i < n; i++) {
		a[i] = readInt() + a[i - 1];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			b[i][j] = readInt();
		}
	}
	for (int i = 0; i < m; i++) {
		b[n][i] = 1e18;
		mono[i][sp[i]++] = n;
	}
	for (int i = 0; i < n; i++) {
		val[i] -= a[i];
	}

	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		memset(imos, 0, sizeof(imos));
		for (int j = 0; j < m; j++) {
			while (b[mono[j][sp[j] - 1]][j] <= b[i][j]) {
				int l = mono[j][sp[j] - 1];
				int r = mono[j][sp[j] - 2];
				long long v = b[l][j];
				sp[j]--;
				imos[l] -= v;
				imos[r] += v;
			}
			int l = i;
			int r = mono[j][sp[j] - 1];
			mono[j][sp[j]++] = i;
			imos[l] += b[i][j];
			imos[r] -= b[i][j];
		}
		for (int j = i; j < n; j++) {
			imos[j + 1] += imos[j];
			val[j] += imos[j];
			ans = max(ans, val[j] + a[i]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8960
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp;
            tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int H = tmp[0];
            int W = tmp[1];
            tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int h = tmp[0];
            int w = tmp[1];

            WriteLine((H - h) * (W - w));
        }
    }
}

Measured memory_bytes: 13268
def kaibun(S):
  N = len(S)
  for i in range(N//2):
    #print(S[i] , S[N-1-i])
    if S[i] != S[N-1-i]:
      return False
  else:
    return True

S = input()
N = len(S)
print("Yes" if ( kaibun(S) and kaibun(S[:N//2]) and kaibun(S[N//2+1:])) else "No")

Measured memory_bytes: 38256
import Data.List

main = interact $ unlines . map (show . sp . map read . words) . filter (elem ' ') . lines

sp = minimum . compress diff . sort
 where diff x y = abs (x-y)

compress _ [x] = [x]
compress op (x1:x2:xs) = op x1 x2 : compress op (x2:xs)

Measured memory_bytes: 5532
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
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; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class BHomework {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n, m;
	    in >> n >> m;
	    vl a(m);
	    ll sum = 0;
	    for(int i=0; i<m; i++){
	        in >> a[i];
	        sum += a[i];
	    }

	    if(n-sum >= 0) out << n-sum << enl;
	    else out << -1 << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	BHomework solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3756
#pragma GCC optimize ("O3")

#pragma GCC optimize("Ofast")

#include   <bits/stdc++.h>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(true);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt"); std::cin.rdbuf(std::cin.rdbuf());
#define    pb(x)            push_back(x)
#define    int              long long int
#define    ull              unsigned long long int
#define    db               long double
#define    mod              1000000007
#define    vll              vector<int>
#define    all(v)           v.rbegin(),v.rend()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)
#define    sz(v)            v.size()
#define    len(S)           S.size()
#define    w(x)             int x; cin>>x; while(x--)



void ipread()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("o.txt","w",stdout);
    #endif
}

void solve()
{

	string s;
	cin>>s;

	if(s.find("7")!=string::npos)
		cout<<"Yes\n";
	else
		cout<<"No\n";

}


int32_t main() {

	//ipread();

  //  w(t){

    	solve();
    //}    

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii a(n);
    int sum = 0;
    rep(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a));
    rep(i, 0, n) {
        if (sum % 10) break;
        if (a[i] % 10) sum -= a[i];
    }
    if (sum % 10 == 0) sum = 0;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

System.out.println(Math.min(a+b,Math.min(a+c,b+c)));


	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> vec(n);
        rep(i,n){
            string s;
            cin >> s;
            vec[i] = len(s);
        }
        rep(i,n){
            int flag = 0;
            int nw = 0;
            bool fl = true;
            srep(j,i,n){
                if(flag == 0){
                    nw += vec[j];
                    if(nw == 5){
                        flag = 1;
                        nw = 0;
                    }else if(nw > 5){
                        fl = false;
                        break;
                    }
                }else if(flag == 1){
                    nw += vec[j];
                    if(nw == 7){
                        flag = 2;
                        nw = 0;
                    }else if(nw > 7){
                        fl = false;
                        break;
                    }
                }else if(flag == 2){
                    nw += vec[j];
                    if(nw == 5){
                        flag = 3;
                        nw = 0;
                    }else if(nw > 5){
                        fl = false;
                        break;
                    }
                }else if(flag == 3){
                    nw += vec[j];
                    if(nw == 7){
                        flag = 4;
                        nw = 0;
                    }else if(nw > 7){
                        fl = false;
                        break;
                    }
                }else{
                    nw += vec[j];
                    if(nw == 7){
                        break;
                    }else if(nw > 7){
                        fl = false;
                        break;
                    }
                }
            }
            if(fl){
                cout << i+1 << "\n";
                break;
            }
        }
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

int N,K;
int A[222222];

int S[222222];
signed main(){
    cin>>N>>K;
    rep(i,N)cin>>A[i];
    rep(i,N)S[i+1]=S[i]+A[i];

    rep(i,N+1)S[i]=(S[i]-i+K*1001001001)%K;

    int ans=0;
    map<int,int>cnt;
    for(int i=0;i<=N;i++){
        if(i>=K){
            cnt[S[i-K]]--;
        }
        ans+=cnt[S[i]];
        cnt[S[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
   int N=int.Parse(Console.ReadLine());
      string[] arr=new string[N];
      for(int i=0;i<N;i++){
       arr[i]=Console.ReadLine(); 
      }
      bool flg=false;
      string[] dis=arr.Distinct().ToArray();
      if(dis.Length!=arr.Length){
        flg=true;
      }else{
        for(int i=1;i<N;i++){
         if(arr[i][0]!=arr[i-1][^1]){
           flg=true;
           break;
         }
          
        }
        
        
      }
      if(flg){
        Console.WriteLine("No");
      }else{
        Console.WriteLine("Yes");
      }
    }
    
  }

}


Measured memory_bytes: 28000
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int d; cin >> d;
    cout << "Christmas";
    rep(i,25-d) cout << " Eve";
    cout << endl;
    return 0;
}


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

int main() {
    long long int n, k;
    cin >> n >> k;
    long long int a[n], tenti[n] = {0}, AtoA[n] = {0};
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) {
        for(int j = i+1; j < n; ++j) {
            if(a[i] > a[j]) tenti[i]++;
            tenti[i] %= MOD;
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(a[i] > a[j]) AtoA[i]++;
            AtoA[i] %= MOD;
        }
    }
    long long int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans = (ans + tenti[i]*k%MOD)%MOD;
        ans = (ans + AtoA[i]*(((k-1)*k/2)%MOD))%MOD;
        ans %= MOD;
    }

    cout << ans << '\n';

    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
	std::vector<int> conv(const std::vector<int> a_, const std::vector<int> b_) {
		std::vector<int> a = a_, b = b_;
		size_t size = 1;
		for (; size < a_.size() + b_.size(); size <<= 1);
		a.resize(size);
		b.resize(size);
		ntt(a, false);
		ntt(b, false);
		for (size_t i = 0; i < size; i++) a[i] = (int64_t) a[i] * b[i] % mod;
		ntt(a, true);
		a.resize(a_.size() + b_.size() - 1);
		return a;
	}
};

int main() {
	int n = ri();
	std::vector<int> count[3];
	std::vector<int> sum[3];
	for (auto &i : count) i.resize(n);
	for (auto &i : sum) i.resize(n + 1);
	std::vector<int> a(n);
	{
		std::string tmp;
		std::cin >> tmp;
		for (int i = 0; i < n; i++) {
			a[i] = tmp[i] == 'R' ? 0 : tmp[i] == 'G' ? 1 : 2;
			count[a[i]][i]++;
			sum[a[i]][i + 1]++;
		}
	}
	for (int i = 0; i < 3; i++) for (int j = 0; j < n; j++) sum[i][j + 1] += sum[i][j];
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		auto &r0 = sum[(a[j] + 1) % 3];
		auto &r1 = sum[(a[j] + 2) % 3];
		res += (int64_t) r0[j] * (r1[n] - r1[j + 1]);
		res += (int64_t) r1[j] * (r0[n] - r0[j + 1]);
	}
	// j - i == k - jで相異なるものを引く
	NTT<998244353, 3> ntt;
	std::vector<int> conved[3][3];
	for (int i = 0; i < 3; i++) for (int j = 0; j < i; j++) conved[i][j] = conved[j][i] = ntt.conv(count[i], count[j]);
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][(a[j] + 2) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    
    vector<vector<char>>a(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    
    for(int i=0;i<w+2;i++){
        cout << "#";
    }
    cout << endl;
    
    for(int i=0;i<h;i++){
        cout << "#";
        for(int j=0;j<w;j++){
            cout << a[i][j];
            if(j==w-1){
                cout << "#" <<endl;
            }
        }
    }
    
    for(int i=0;i<w+2;i++){
        cout << "#";
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main(){
    int n, res;
    while(cin >> n){
        res = 0;
        for(int a = 0; a <= 9; a++)
            for(int b = 0; b <= 9; b++)
                for(int c = 0; c <= 9; c++)
                    for(int d = 0; d <= 9; d++)
                        if( a + b + c + d == n) res++;
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=1; i<=(n);i++)
typedef long long ll;

int main(){
    double l; cin >> l;
    cout << fixed << setprecision(10) << pow((l/3), 3) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,m;cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  
  int sum = 0;
  rep(i,m) sum += a[i];
  int res = n - sum;
  if(res < 0) res = -1;
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3216
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
struct item {
	int wght, val;
};
int n, W;
ll dp[101][100005];
vector<item> v;
ll calc(int idx, int value) {
	if (value == 0)
		return 0;
	if (idx == n)
		return W+1;
	ll &ret = dp[idx][value];
	if (ret != -1)
		return ret;
	ret = calc(idx + 1, value);
	if (value - v[idx].val >= 0)
		ret = min(ret, v[idx].wght + calc(idx + 1, value - v[idx].val));
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n >> W;
	v.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i].wght >> v[i].val;
	int ans = 0;
	for (int val = 1; val <= 100000; ++val) {
		if (calc(0, val) <= W)
			ans = max(ans, val);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n, m;
    cin >> n >> m;
    vector<pll> ab(n);
    for(int i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(all(ab));
    ll ans = 0;
    ll num = 0;
    for(int i = 0; i < n; i++){
        if(num + ab[i].second < m){
            ans += ab[i].first*ab[i].second;
            num += ab[i].second;
        }else if(num + ab[i].second == m){
            ans += ab[i].first*ab[i].second;
            num += ab[i].second;
            break;
        }else{
            ans += ab[i].first*(m-num);
            num += (m-num);
            break;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    while(cin >> N >> M && N){
        vec<int> ma(M+1);
        for(int i=0;i<N;i++){
            int c,d;
            cin >> c >> d;
            ma[c] = max(ma[c],d);
        }
        cout << accumulate(ma.begin(),ma.end(),0) << "\n";
    }
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

bool query(ll n) {
    cout << "? " << n << endl << flush;
    char c;
    cin >> c;
    return c == 'Y';
}

int main() {
    ll N = 0;
    rep(i, 10) {
        const ll padding = i < 5 ? 1'000'000'000LL : 1'000'000LL;
        int low = i == 0 ? 0 : -1, high = 9;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (query((N * 10 + mid) * padding + padding - 1)) high = mid;
            else low = mid;
        }

        if (high == 0 && query(N + 1) ^ (to_string(N).size() != to_string(N + 1).size())) {
            break;
        }
        else {
            N = N * 10 + high;
        }
        // write(N);
    }

    cout << "! " << N << endl;
}

Measured memory_bytes: 624
import sys
ks = list(map(int, input().split()))
k = ks[0]
s = ks[1]
ans = 0
for x in range(k+1):
  for y in range(k+1):
    if s - x - y <= k and s - x - y >=0:
      ans = ans + 1
      
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    string s ; cin >> s;
    int num = s.size()-2;
    cout << s[0] << num << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

ll f(ll h)
{
    if (h == 1) return 1;
    return 2*f(h/2) + 1;
}

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int n, l;
    cin >> n >> l;

    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
    }

    sort(s.begin(), s.end());

    for(auto i : s) {
        cout << i;
    }

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int gcd(int x, int y);
int main(){
  int a,b;
  while(cin >>a>>b){
    int c = gcd(a,b);
    cout <<c<<" "<<a/c*b<<endl;
  }
  return 0;
}
int gcd(int x, int y){
  if(y == 0) return x;
  return gcd(y,x%y);
}

Measured memory_bytes: 1160
H, W = map(int, input().split(' '))
a = [['0' for _ in range(W + 1)] for _ in range(H + 1)]
dp = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
for i in range(H):
  str_a = input()
  for j in range(W):
     a[i+1][j+1] = str_a[j]
i, j = 1, 1
while i <= H and a[i][1] == '.':
  dp[i][1] = 1
  i += 1
while j <= W and a[1][j] == '.':
  dp[1][j] = 1
  j += 1
for i in range(2, H + 1):
  for j in range(2, W + 1):
    if a[i][j] == '.':
      dp[i][j] = dp[i-1][j] + dp[i][j-1]
print(dp[H][W] % 1000000007)

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

int main(){

    int a,b,c,i,j,k;
    cin>>a>>b>>c;

    i=a+b;
    j=a+c;
    k=b+c;

    if(i<j&&i<k){
        cout<<i<<endl;
    }
    else if(j<i&&j<k){
        cout<<j<<endl;
    }
    else{
        cout<<k<<endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int h[n];
    int cost[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    cost[0]=0;
    cost[1]=abs(h[1]-h[0]);
    cost[2]=min(abs(h[2]-h[1])+cost[1],abs(h[2]-h[0])+cost[0]);
    for(int i=3;i<n;i++){
        cost[i]=min(abs(h[i]-h[i-1])+cost[i-1],abs(h[i]-h[i-2])+cost[i-2]);
    }
    cout<<cost[n-1];
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;


int main() {
    int n;
    cin >> n;
    vll nums(n);
    ll sum = 0;
    ll maxEdge = INT_MIN;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        sum += nums[i];
        maxEdge = max(maxEdge, nums[i]);
    }
    if (sum - maxEdge > maxEdge) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;

    map<int, int> mp;
    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            int d;
            d = min(j-i, abs(x-i)+abs(y-j) + 1);
            mp[d]++;
        }
    }
    for (int i = 0; i < n - 1; ++i) {
        cout << mp[i+1] << endl;
    }
}

Measured memory_bytes: 384
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    print(max(a+b,a-b,a*b))
    return

#B
def B():
    k,x = LI()
    ans = []
    for i in range(x-k+1,x+k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    def f(s):
        res = [0]*m
        for i in s:
            res[alp.index(i)] += 1
        return res
    alp = list("abcdefghijklmnopqrstuvwxyz")
    m = len(alp)
    n = I()
    s = [input() for i in range(n)]
    d = defaultdict(lambda : 0)
    for i in s:
        d[tuple(f(i))] += 1
    ans = 0
    for i in d.values():
        ans += (i*(i-1))//2
    print(ans)
    return

#D
def D():
    n,m = LI()
    g = LIR(n)
    g.sort(key = lambda x:x[0])
    ans = 0
    f = [1]*n
    j = 0
    q = []
    for i in range(m)[::-1]:
        while j < n and m-g[j][0] >= i:
            a,b = g[j]
            heappush(q,(-b,a))
            j += 1
        if q:
            x,a = heappop(q)
            if i+a <= m:
                ans -= x
    print(ans)
    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 82396
package main

import (
	"errors"
	"fmt"
	"os"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	if s[:1] != "d" && s[:1] != "e" {
		fmt.Println("NO")
		os.Exit(0)
	}

	for {
		var err error
		s, err = removeMatchedStr(s)
		if err != nil {
			fmt.Println("NO")
			os.Exit(0)
		}
		if len(s) == 0 {
			break
		}
	}
	fmt.Println("YES")
}

func removeMatchedStr(s string) (string, error) {
	// dreamRegex := regexp.MustCompile(`\w.dream$`)
	// dreamerRegex := regexp.MustCompile(`\w.dreamer$`)
	// eraseRegex := regexp.MustCompile(`\w.erase$`)
	// eraserRegex := regexp.MustCompile(`\w.eraser$`)
	if s == "dreamer" || s == "dream" || s == "eraser" || s == "erase" {
		return "", nil
	}

	// if dreamerRegex.MatchString(s) {
	if strings.HasSuffix(s, "dreamer") {
		return strings.TrimSuffix(s, "dreamer"), nil
	}

	// if dreamRegex.MatchString(s) {

	if strings.HasSuffix(s, "dream") {
		return strings.TrimSuffix(s, "dream"), nil
	}

	// if eraserRegex.MatchString(s) {

	if strings.HasSuffix(s, "eraser") {
		return strings.TrimSuffix(s, "eraser"), nil
	}

	// if eraseRegex.MatchString(s) {

	if strings.HasSuffix(s, "erase") {
		return strings.TrimSuffix(s, "erase"), nil
	}

	return "", errors.New("string is not found")
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(x, N, 1000) if (x % 111 == 0) {
        cout << x << endl;
        return;
    }
}


Measured memory_bytes: 256
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]

visited = {}
dist = {}
for i in range(10):
    dist[i] = 100000
dist[1] = 0

while len(dist) > 0:
    cur, curDist = sorted(dist.items(), key=lambda x: x[1])[0]
    del dist[cur]
    visited[cur] = curDist

    for i in range(10):
        if i == cur or i in visited:
            continue

        newDist = curDist + c[i][cur]
        dist[i] = min(dist[i], newDist)

cnts = [0] * 10
for _ in range(h):
    a = list(map(int, input().split()))
    for ai in a:
        if ai != -1:
            cnts[ai] += 1

cnt = 0
for i in range(10):
    cnt += cnts[i]*visited[i]

print(cnt)

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

int		main(void)
{
	int n;

	cin >> n;
	for (int i = 111; i < 1000; i+= 111)
	{
		if (n <= i)
		{
			cout << i << endl;
			return (0);
		}
	}
}


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

vector<string> fix(vector<string> v){
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	int bad[20] = {};
	for(int i = 0 ; i < v.size() ; i++){
		for(int j = 0 ; j < v.size() ; j++){
			if( i != j && ~v[i].find(v[j]) ){
				bad[j] = 1;
			}
		}
	}
	vector<string> res;
	for(int i = 0 ; i < v.size() ; i++){
		if( bad[i] == 0 ) res.push_back(v[i]);
	}
	return res;
}

int dp[1<<14][14];

int main(){
	int n;
	while(cin >> n && n){
		vector<string> v(n);
		for(int i = 0 ; i < n ; i++)
			cin >> v[i];
		v = fix(v);
		n = v.size();
		int g[20][20] = {};
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				int res = v[j].size();
				int len = min(v[i].size(),v[j].size());
				for(int k = 0 ; k < v[i].size() ; k++){
					string A = v[i].substr(k);
					if( A.size() > len ) continue;
					string B = v[j].substr(0,A.size());
					//cout << A << " " << B << endl;
					if( A == B ){
						res = min( res , (int)(v[j].size() - A.size()) );
					}
				}
				g[i][j] = res;
				//cout << i << "," << j << " = " << g[i][j] << endl;
			}
		}
		for(int i = 0 ; i < (1<<14) ; i++)
			for(int j = 0 ; j < 14 ; j++)
				dp[i][j] = 1e9;
		for(int i = 0 ; i < n ; i++){
			dp[(1<<i)][i] = v[i].size();
		}
		for(int i = 0 ; i < (1<<n) ; i++){
			for(int j = 0 ; j < n ; j++){
				for(int k = 0 ; k < n ; k++){
					dp[i|(1<<k)][k] = min( dp[i|(1<<k)][k] , dp[i][j] + g[j][k] );
				}
			}
		}
		int ans = 1e9;
		for(int i = 0 ; i < n ; i++){
			ans = min(ans,dp[(1<<n)-1][i]);
		}
		cout << ans << endl;
		
	}
}

Measured memory_bytes: 2120
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
    mt19937 gen(857204);
#else
    mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

signed main() {
    FAST; FIXED;
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1];
    #ifdef DEBUG
        cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main() {

    while (true) {
        int m, f, r = 0;
        std::string result;
        std::cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1) break;

        if (m == -1 || f == -1) result = "F";
        else if (m + f >= 80) result = "A";
        else if (m + f >= 65) result = "B";
        else if (m + f >= 50) result = "C";
        else if (m + f >= 30 && r >= 50) result = "C";
        else if (m + f >= 30) result = "D";
        else result ="F";

        std::cout << result << std::endl;
    }
}


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

using namespace std;
using namespace std;
typedef long long ll;
#define endl "\n";
#define MAX 10000001+9   //Maximum array size;
#define loop(n) for(ll i=0;i<n;i++)
#define loop2(n) for(ll i=0;i<n;i+=2)
#define all(v) v.begin(),v.end()
#define sz(v)  v.size()
typedef vector<ll> vi;
typedef set<ll> si;

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

int pow(int a, int b) {
    int pow = 1;
    loop(b)pow *= a;
    return pow;
    //thanks m7md :)
}

int main() {
    fast();
  //freopen("input.txt","r",stdin);
    int n;cin>>n;
    string s;cin>>s;
    int k;cin>>k;
    for (int i = 0; i <n ; ++i) {
        if(s[i]!=s[k-1])s[i]='*';
    }
    cout<<s;

}



Measured memory_bytes: 256
/**
 *   
 *   Date: 18 August 2019
 *   Time: 18:03:12
**/
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll val[200100],beg[200100],en[200100],br[200100],tt,ar[200100];
bool vis[200100];
vec adj[200100];
void dfs(ll s,ll p)
{
	vis[s]=true;
	tt+=1;
	val[tt]=s;
	beg[s]=tt;
	for(auto it=adj[s].begin();it != adj[s].end();it++)
	{
		if(*it == p)
			continue;
		if(!vis[*it])
			dfs(*it,s);
	}
	en[s]=tt;
}
int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,q,u,v,d,d1,x;
	cin>>n>>q;
	for(ll i=1;i<n;i++)
	{
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1,-1);
	while(q--)
	{
		cin>>u>>x;
		d=beg[u];
		d1=en[u];
		ar[d]+=x;
		ar[d1+1]-=x;
	}
	for(ll i=1;i<=n;i++)
	{
		ar[i]+=ar[i-1];
	}
	for(ll i=1;i<=n;i++)
	{
		br[val[i]]=ar[i];
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<br[i]<<" ";
	}

return 0;
}

Measured memory_bytes: 30720
#include <bits/stdc++.h>
using namespace std;
string a;
int l,c=0,f=0,s=0;
int main()
{
    cin>>a;
    l=a.size();
    for(int i=0;i<l;++i)
    {
    	if(a[i]=='C') ++c;
    	if(a[i]=='F') ++f;
    	if(f==1&&c==0) f=0;
	}
	if((c>=1)&&(f>=1)) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256